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
|
2023-02-09 15:29:33 +00:00
|
|
|
* Copyright (C) 2018-2023 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
|
|
|
|
*/
|
|
|
|
|
2021-03-13 20:19:46 +00:00
|
|
|
#include "drawing_tool.h"
|
2022-04-11 15:09:27 +00:00
|
|
|
#include "geometry/shape_rect.h"
|
2021-09-02 22:32:15 +00:00
|
|
|
|
2021-10-24 12:15:53 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2021-08-29 23:33:08 +00:00
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <footprint_editor_settings.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <dialogs/dialog_text_properties.h>
|
|
|
|
#include <dialogs/dialog_track_via_size.h>
|
|
|
|
#include <geometry/geometry_utils.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <import_gfx/dialog_import_gfx.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <preview_items/two_point_assistant.h>
|
|
|
|
#include <preview_items/two_point_geom_manager.h>
|
|
|
|
#include <ratsnest/ratsnest_data.h>
|
|
|
|
#include <router/router_tool.h>
|
2014-02-13 11:46:39 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2021-01-16 23:17:32 +00:00
|
|
|
#include <tools/pcb_grid_helper.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2020-12-01 14:58:33 +00:00
|
|
|
#include <tools/tool_event_utils.h>
|
|
|
|
#include <tools/zone_create_helper.h>
|
2022-11-14 23:39:08 +00:00
|
|
|
#include <tools/zone_filler_tool.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <view/view.h>
|
2021-04-05 22:29:12 +00:00
|
|
|
#include <widgets/appearance_controls.h>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2022-02-08 19:29:54 +00:00
|
|
|
#include <wx/filedlg.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <board_commit.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <painter.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2022-02-08 19:29:54 +00:00
|
|
|
#include <pcb_bitmap.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <pcb_textbox.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2020-08-31 22:32:11 +00:00
|
|
|
#include <pcbnew_id.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <preview_items/arc_assistant.h>
|
|
|
|
#include <scoped_set_reset.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-09-02 22:32:15 +00:00
|
|
|
#include <zone.h>
|
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
const unsigned int DRAWING_TOOL::COORDS_PADDING = pcbIUScale.mmToIU( 20 );
|
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
|
|
|
|
2020-08-31 22:32:11 +00:00
|
|
|
class VIA_SIZE_MENU : public ACTION_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VIA_SIZE_MENU() :
|
|
|
|
ACTION_MENU( true )
|
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
SetIcon( BITMAPS::width_track_via );
|
2020-08-31 22:32:11 +00:00
|
|
|
SetTitle( _( "Select Via Size" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ACTION_MENU* create() const override
|
|
|
|
{
|
|
|
|
return new VIA_SIZE_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
void update() override
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) getToolManager()->GetToolHolder();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = frame->GetBoard()->GetDesignSettings();
|
|
|
|
bool useIndex = !bds.m_UseConnectedTrackWidth
|
|
|
|
&& !bds.UseCustomTrackViaSize();
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Use Custom Values..." ),
|
|
|
|
_( "Specify custom track and via sizes" ), wxITEM_CHECK );
|
|
|
|
Check( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, bds.UseCustomTrackViaSize() );
|
|
|
|
|
|
|
|
AppendSeparator();
|
|
|
|
|
|
|
|
for( unsigned i = 1; i < bds.m_ViasDimensionsList.size(); i++ )
|
|
|
|
{
|
|
|
|
VIA_DIMENSION via = bds.m_ViasDimensionsList[i];
|
|
|
|
|
|
|
|
if( via.m_Drill > 0 )
|
2020-12-01 14:58:33 +00:00
|
|
|
{
|
2022-03-03 21:47:05 +00:00
|
|
|
msg.Printf( _("Via %s, hole %s" ),
|
2022-09-19 09:25:20 +00:00
|
|
|
frame->MessageTextFromValue( via.m_Diameter ),
|
|
|
|
frame->MessageTextFromValue( via.m_Drill ) );
|
2020-12-01 14:58:33 +00:00
|
|
|
}
|
2020-08-31 22:32:11 +00:00
|
|
|
else
|
2020-12-01 14:58:33 +00:00
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
msg.Printf( _( "Via %s" ),
|
|
|
|
frame->MessageTextFromValue( via.m_Diameter ) );
|
2020-12-01 14:58:33 +00:00
|
|
|
}
|
2020-08-31 22:32:11 +00:00
|
|
|
|
|
|
|
int menuIdx = ID_POPUP_PCB_SELECT_VIASIZE1 + i;
|
|
|
|
Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK );
|
|
|
|
Check( menuIdx, useIndex && bds.GetViaSizeIndex() == i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) getToolManager()->GetToolHolder();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = frame->GetBoard()->GetDesignSettings();
|
|
|
|
int id = aEvent.GetId();
|
|
|
|
|
|
|
|
// On Windows, this handler can be called with an event ID not existing in any
|
|
|
|
// menuitem, so only set flags when we have an ID match.
|
|
|
|
|
|
|
|
if( id == ID_POPUP_PCB_SELECT_CUSTOM_WIDTH )
|
|
|
|
{
|
|
|
|
DIALOG_TRACK_VIA_SIZE sizeDlg( frame, bds );
|
|
|
|
|
2021-02-08 17:39:40 +00:00
|
|
|
if( sizeDlg.ShowModal() == wxID_OK )
|
2020-08-31 22:32:11 +00:00
|
|
|
{
|
|
|
|
bds.UseCustomTrackViaSize( true );
|
|
|
|
bds.m_UseConnectedTrackWidth = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( id >= ID_POPUP_PCB_SELECT_VIASIZE1 && id <= ID_POPUP_PCB_SELECT_VIASIZE16 )
|
|
|
|
{
|
|
|
|
bds.UseCustomTrackViaSize( false );
|
|
|
|
bds.m_UseConnectedTrackWidth = false;
|
|
|
|
bds.SetViaSizeIndex( id - ID_POPUP_PCB_SELECT_VIASIZE1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPT_TOOL_EVENT( PCB_ACTIONS::trackViaSizeChanged.MakeEvent() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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" ),
|
2021-02-01 22:45:56 +00:00
|
|
|
m_view( nullptr ),
|
|
|
|
m_controls( nullptr ),
|
|
|
|
m_board( nullptr ),
|
|
|
|
m_frame( nullptr ),
|
|
|
|
m_mode( MODE::NONE ),
|
2021-06-26 17:44:18 +00:00
|
|
|
m_inDrawingTool( false ),
|
2021-10-22 16:00:55 +00:00
|
|
|
m_layer( UNDEFINED_LAYER ),
|
2021-07-17 19:56:18 +00:00
|
|
|
m_stroke( 1, PLOT_DASH_TYPE::DEFAULT, COLOR4D::UNSPECIFIED )
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRAWING_TOOL::~DRAWING_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
bool DRAWING_TOOL::Init()
|
|
|
|
{
|
2022-07-10 23:14:29 +00:00
|
|
|
auto haveHighlight =
|
|
|
|
[&]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
KIGFX::RENDER_SETTINGS* cfg = m_toolMgr->GetView()->GetPainter()->GetSettings();
|
|
|
|
|
|
|
|
return !cfg->GetHighlightNetCodes().empty();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto activeToolFunctor =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
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
|
2022-07-10 23:14:29 +00:00
|
|
|
auto canUndoPoint =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return ( m_mode == MODE::ARC
|
|
|
|
|| m_mode == MODE::ZONE
|
|
|
|
|| m_mode == MODE::KEEPOUT
|
|
|
|
|| m_mode == MODE::GRAPHIC_POLYGON );
|
|
|
|
};
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2020-04-24 17:34:05 +00:00
|
|
|
// functor for tools that can automatically close the outline
|
2022-07-10 23:14:29 +00:00
|
|
|
auto canCloseOutline =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return ( m_mode == MODE::ZONE
|
|
|
|
|| m_mode == MODE::KEEPOUT
|
|
|
|
|| m_mode == MODE::GRAPHIC_POLYGON );
|
|
|
|
};
|
|
|
|
|
2022-10-07 05:28:05 +00:00
|
|
|
auto arcToolActive =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_mode == MODE::ARC;
|
|
|
|
};
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
auto viaToolActive =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_mode == MODE::VIA;
|
|
|
|
};
|
2020-08-31 22:32:11 +00:00
|
|
|
|
2022-07-30 12:22:01 +00:00
|
|
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
2017-02-06 16:00:51 +00:00
|
|
|
|
2018-08-01 16:58:27 +00:00
|
|
|
// cancel current tool goes in main context menu at the top if present
|
2022-07-10 23:14:29 +00:00
|
|
|
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
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::clearHighlight, haveHighlight, 2 );
|
|
|
|
ctxMenu.AddSeparator( haveHighlight, 2 );
|
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
// tool-specific actions
|
2022-07-10 23:14:29 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::closeOutline, canCloseOutline, 200 );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
|
2022-10-07 05:28:05 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::arcPosture, arcToolActive, 200 );
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2022-05-29 13:16:13 +00:00
|
|
|
ctxMenu.AddCheckItem( PCB_ACTIONS::toggleHV45Mode, SELECTION_CONDITIONS::ShowAlways, 250 );
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator( 500 );
|
2017-02-06 16:00:51 +00:00
|
|
|
|
2020-08-31 22:32:11 +00:00
|
|
|
std::shared_ptr<VIA_SIZE_MENU> viaSizeMenu = std::make_shared<VIA_SIZE_MENU>();
|
|
|
|
viaSizeMenu->SetTool( this );
|
2022-09-03 18:29:02 +00:00
|
|
|
m_menu.RegisterSubMenu( viaSizeMenu );
|
2022-07-10 23:14:29 +00:00
|
|
|
ctxMenu.AddMenu( viaSizeMenu.get(), viaToolActive, 500 );
|
2020-08-31 22:32:11 +00:00
|
|
|
|
|
|
|
ctxMenu.AddSeparator( 500 );
|
|
|
|
|
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>();
|
2021-10-24 12:15:53 +00:00
|
|
|
|
2023-06-13 10:05:16 +00:00
|
|
|
// Re-initialize session attributes
|
|
|
|
const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings();
|
|
|
|
|
|
|
|
m_layer = m_frame->GetActiveLayer();
|
|
|
|
m_stroke.SetWidth( bds.GetLineThickness( m_layer ) );
|
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
|
|
|
|
|
|
|
m_textAttrs.m_Size = bds.GetTextSize( m_layer );
|
|
|
|
m_textAttrs.m_StrokeWidth = bds.GetTextThickness( m_layer );
|
|
|
|
InferBold( &m_textAttrs );
|
|
|
|
m_textAttrs.m_Italic = bds.GetTextItalic( m_layer );
|
|
|
|
m_textAttrs.m_KeepUpright = bds.GetTextUpright( m_layer );
|
|
|
|
m_textAttrs.m_Mirrored = IsBackLayer( m_layer );
|
|
|
|
m_textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
m_textAttrs.m_Valign = GR_TEXT_V_ALIGN_TOP;
|
|
|
|
|
2022-07-27 12:37:20 +00:00
|
|
|
UpdateStatusBar();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-27 12:37:20 +00:00
|
|
|
void DRAWING_TOOL::UpdateStatusBar() const
|
2021-10-24 12:15:53 +00:00
|
|
|
{
|
|
|
|
if( m_frame )
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
bool constrained;
|
2021-10-24 12:15:53 +00:00
|
|
|
|
|
|
|
if( m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2021-08-29 23:33:08 +00:00
|
|
|
constrained = mgr.GetAppSettings<PCBNEW_SETTINGS>()->m_Use45DegreeLimit;
|
2021-10-24 12:15:53 +00:00
|
|
|
else
|
2021-08-29 23:33:08 +00:00
|
|
|
constrained = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>()->m_Use45Limit;
|
2021-10-24 12:15:53 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_frame->DisplayConstraintsMsg( constrained ? _( "Constrain to H, V, 45" ) : wxString( "" ) );
|
2021-10-24 12:15:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
|
2014-02-06 16:12:37 +00:00
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2018-05-14 03:22:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
BOARD_ITEM* parent = m_frame->GetModel();
|
|
|
|
PCB_SHAPE* line = new PCB_SHAPE( parent );
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );
|
|
|
|
std::optional<VECTOR2D> startingPoint;
|
2023-06-19 16:09:03 +00:00
|
|
|
std::stack<PCB_SHAPE*> committedLines;
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
line->SetShape( SHAPE_T::SEGMENT );
|
2019-06-24 15:27:05 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
2021-05-09 19:17:01 +00:00
|
|
|
startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2014-04-04 09:50:15 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-16 10:03:56 +00:00
|
|
|
Activate();
|
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
while( drawShape( aEvent, &line, startingPoint, &committedLines ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( line )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( line );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Draw Line" ) );
|
2017-11-01 11:14:16 +00:00
|
|
|
startingPoint = VECTOR2D( line->GetEnd() );
|
2023-06-19 16:09:03 +00:00
|
|
|
committedLines.push( line );
|
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
|
|
|
{
|
2022-08-25 22:50:47 +00:00
|
|
|
startingPoint = std::nullopt;
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
line = new PCB_SHAPE( parent );
|
2021-07-21 18:31:25 +00:00
|
|
|
line->SetShape( SHAPE_T::SEGMENT );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2020-06-15 19:50:20 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
bool isTextBox = aEvent.IsAction( &PCB_ACTIONS::drawTextBox );
|
|
|
|
PCB_SHAPE* rect = nullptr;
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
BOARD_ITEM* parent = m_frame->GetModel();
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE );
|
|
|
|
std::optional<VECTOR2D> startingPoint;
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
rect = isTextBox ? new PCB_TEXTBOX( parent ) : new PCB_SHAPE( parent );
|
2023-07-24 16:07:56 +00:00
|
|
|
rect->SetShape( SHAPE_T::RECTANGLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
rect->SetFilled( false );
|
2022-06-03 17:47:03 +00:00
|
|
|
rect->SetFlags( IS_NEW );
|
2020-06-15 19:50:20 +00:00
|
|
|
|
|
|
|
if( aEvent.HasPosition() )
|
2021-05-09 19:17:01 +00:00
|
|
|
startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2020-06-15 19:50:20 +00:00
|
|
|
Activate();
|
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
while( drawShape( aEvent, &rect, startingPoint, nullptr ) )
|
2020-06-15 19:50:20 +00:00
|
|
|
{
|
|
|
|
if( rect )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
bool cancelled = false;
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( PCB_TEXTBOX* textbox = dynamic_cast<PCB_TEXTBOX*>( rect ) )
|
|
|
|
cancelled = m_frame->ShowTextBoxPropertiesDialog( textbox ) != wxID_OK;
|
|
|
|
|
|
|
|
if( cancelled )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
|
|
|
delete rect;
|
|
|
|
rect = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-07 17:39:10 +00:00
|
|
|
rect->NormalizeRect();
|
2022-01-30 10:52:52 +00:00
|
|
|
commit.Add( rect );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( isTextBox ? _( "Draw Text Box" ) : _( "Draw Rectangle" ) );
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, rect );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
rect = isTextBox ? new PCB_TEXTBOX( parent ) : new PCB_SHAPE( parent );
|
2023-07-24 16:07:56 +00:00
|
|
|
rect->SetShape( SHAPE_T::RECTANGLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
rect->SetFilled( false );
|
2022-06-03 17:47:03 +00:00
|
|
|
rect->SetFlags( IS_NEW );
|
2022-08-25 22:50:47 +00:00
|
|
|
startingPoint = std::nullopt;
|
2020-06-15 19:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
|
2014-02-10 09:58:58 +00:00
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2018-05-14 03:22:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
BOARD_ITEM* parent = m_frame->GetModel();
|
|
|
|
PCB_SHAPE* circle = new PCB_SHAPE( parent );
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );
|
|
|
|
std::optional<VECTOR2D> startingPoint;
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
circle->SetShape( SHAPE_T::CIRCLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
circle->SetFilled( false );
|
2019-06-15 19:42:17 +00:00
|
|
|
circle->SetFlags( IS_NEW );
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aEvent.HasPosition() )
|
2021-05-09 19:17:01 +00:00
|
|
|
startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2014-02-14 10:35:48 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-16 10:03:56 +00:00
|
|
|
Activate();
|
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
while( drawShape( aEvent, &circle, startingPoint, nullptr ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( circle )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( circle );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Draw Circle" ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, circle );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
circle = new PCB_SHAPE( parent );
|
2021-07-21 18:31:25 +00:00
|
|
|
circle->SetShape( SHAPE_T::CIRCLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
circle->SetFilled( false );
|
2019-06-15 19:42:17 +00:00
|
|
|
circle->SetFlags( IS_NEW );
|
2022-05-16 09:22:55 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
startingPoint = std::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 )
|
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2018-05-14 03:22:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
BOARD_ITEM* parent = m_frame->GetModel();
|
|
|
|
PCB_SHAPE* arc = new PCB_SHAPE( parent );
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC );
|
|
|
|
std::optional<VECTOR2D> startingPoint;
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
arc->SetShape( SHAPE_T::ARC );
|
2019-06-15 19:42:17 +00:00
|
|
|
arc->SetFlags( IS_NEW );
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2019-06-24 15:27:05 +00:00
|
|
|
Activate();
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2022-05-16 09:22:55 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
startingPoint = aEvent.Position();
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
while( drawArc( aEvent, &arc, startingPoint ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
|
|
|
if( arc )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( arc );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Draw Arc" ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, arc );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
arc = new PCB_SHAPE( parent );
|
2021-07-21 18:31:25 +00:00
|
|
|
arc->SetShape( SHAPE_T::ARC );
|
2019-06-15 19:42:17 +00:00
|
|
|
arc->SetFlags( IS_NEW );
|
2022-05-16 09:22:55 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
startingPoint = std::nullopt;
|
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
|
|
|
|
|
|
|
|
2022-02-08 19:29:54 +00:00
|
|
|
int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
|
|
|
|
2022-07-30 12:22:01 +00:00
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2022-07-30 12:22:01 +00:00
|
|
|
PCB_BITMAP* image = aEvent.Parameter<PCB_BITMAP*>();
|
|
|
|
bool immediateMode = image != nullptr;
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
|
|
|
bool ignorePrimePosition = false;
|
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2022-07-30 12:22:01 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
// Add all the drawable symbols to preview
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
image->SetPosition( cursorPos );
|
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2022-02-08 19:29:54 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2022-02-08 19:29:54 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( image )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2022-02-08 19:29:54 +00:00
|
|
|
m_view->ClearPreview();
|
2023-02-17 00:29:27 +00:00
|
|
|
m_view->RecacheAllItems();
|
2022-02-08 19:29:54 +00:00
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
|
|
|
// Prime the pump
|
|
|
|
if( image )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-02-08 19:29:54 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.HasPosition() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
|
|
|
}
|
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
2022-11-30 18:57:42 +00:00
|
|
|
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
cursorPos = GetClampedCoords(
|
|
|
|
grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ),
|
|
|
|
COORDS_PADDING );
|
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( image && evt->IsAction( &ACTIONS::undo ) ) )
|
2022-02-08 19:29:54 +00:00
|
|
|
{
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2022-02-08 19:29:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( immediateMode )
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2022-02-08 19:29:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( image && evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// We're already moving our own item; ignore the move tool
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( image )
|
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel image creation." ) );
|
|
|
|
evt->SetPassEvent( false );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
|
|
|
{
|
|
|
|
// Leave ourselves on the stack so we come back after the move
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2022-02-08 19:29:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( !image )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
|
|
|
|
_( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
|
|
|
|
wxFD_OPEN );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If we started with a hotkey which has a position then warp back to that.
|
|
|
|
// Otherwise update to the current mouse position pinned inside the autoscroll
|
|
|
|
// boundaries.
|
|
|
|
if( evt->IsPrime() && !ignorePrimePosition )
|
|
|
|
{
|
|
|
|
cursorPos = grid.Align( evt->Position() );
|
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getViewControls()->PinCursorInsideNonAutoscrollArea( true );
|
|
|
|
cursorPos = getViewControls()->GetMousePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
cursorPos = getViewControls()->GetMousePosition( true );
|
|
|
|
|
|
|
|
wxString fullFilename = dlg.GetPath();
|
|
|
|
|
|
|
|
if( wxFileExists( fullFilename ) )
|
|
|
|
image = new PCB_BITMAP( m_frame->GetModel(), cursorPos );
|
|
|
|
|
|
|
|
if( !image || !image->ReadImageFile( fullFilename ) )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
|
|
|
|
delete image;
|
|
|
|
image = nullptr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
image->SetFlags( IS_NEW | IS_MOVING );
|
|
|
|
image->SetLayer( m_frame->GetActiveLayer() );
|
|
|
|
|
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2022-02-08 19:29:54 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
|
|
|
selectionTool->AddItemToSel( image, false );
|
|
|
|
|
|
|
|
getViewControls()->SetCursorPosition( cursorPos, false );
|
|
|
|
setCursor();
|
|
|
|
m_view->ShowPreview( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.Add( image );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Place Image" ) );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, image );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
image = nullptr;
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::activatePointEditor );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
m_view->ClearPreview();
|
|
|
|
|
|
|
|
if( immediateMode )
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2022-02-08 19:29:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
// Warp after context menu only if dragging...
|
|
|
|
if( !image )
|
|
|
|
m_toolMgr->VetoContextMenuMouseWarp();
|
|
|
|
|
|
|
|
m_menu.ShowContextMenu( selectionTool->GetSelection() );
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( image && ( evt->IsAction( &ACTIONS::refreshPreview )
|
|
|
|
|| evt->IsMotion() ) )
|
2022-02-08 19:29:54 +00:00
|
|
|
{
|
|
|
|
image->SetPosition( cursorPos );
|
|
|
|
m_view->ClearPreview();
|
2022-09-19 14:39:17 +00:00
|
|
|
m_view->AddToPreview( image, false ); // Add, but not give ownership
|
2022-02-08 19:29:54 +00:00
|
|
|
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
|
|
|
|
}
|
|
|
|
else if( image && evt->IsAction( &ACTIONS::doDelete ) )
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( image && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2022-02-08 19:29:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is an image to be placed
|
|
|
|
getViewControls()->SetAutoPan( image != nullptr );
|
|
|
|
getViewControls()->CaptureCursor( image != nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
getViewControls()->CaptureCursor( false );
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2018-05-14 03:22:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* text = nullptr;
|
2022-05-16 22:41:30 +00:00
|
|
|
bool ignorePrimePosition = false;
|
2022-06-03 17:47:03 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings();
|
2021-04-07 13:50:18 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
|
2022-11-30 18:57:42 +00:00
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
2021-04-07 13:50:18 +00:00
|
|
|
|
|
|
|
auto cleanup =
|
|
|
|
[&]()
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2021-04-07 13:50:18 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
delete text;
|
2021-07-19 23:56:05 +00:00
|
|
|
text = nullptr;
|
2021-04-07 13:50:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( text )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
|
|
|
else
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
|
|
|
|
};
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2016-06-08 09:24:46 +00:00
|
|
|
Activate();
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
m_controls->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// do not capture or auto-pan until we start placing some text
|
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
{
|
2022-05-16 09:22:55 +00:00
|
|
|
m_toolMgr->PrimeTool( aEvent.Position() );
|
2022-05-16 22:41:30 +00:00
|
|
|
}
|
|
|
|
else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
|
|
|
|
{
|
|
|
|
m_toolMgr->PrimeTool( { 0, 0 } );
|
|
|
|
ignorePrimePosition = true;
|
|
|
|
}
|
2019-06-24 15:27:05 +00:00
|
|
|
|
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
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2022-11-30 18:57:42 +00:00
|
|
|
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
VECTOR2I cursorPos = GetClampedCoords(
|
|
|
|
grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ),
|
|
|
|
COORDS_PADDING );
|
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-02-10 09:58:58 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( text && evt->IsAction( &ACTIONS::undo ) ) )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2016-06-08 09:24:46 +00:00
|
|
|
if( text )
|
2021-04-07 13:50:18 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2021-04-07 13:50:18 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2020-11-08 00:14:22 +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
|
|
|
|
2022-06-03 17:47:03 +00:00
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
TEXT_ATTRIBUTES textAttrs;
|
|
|
|
|
|
|
|
textAttrs.m_Size = bds.GetTextSize( layer );
|
|
|
|
textAttrs.m_StrokeWidth = bds.GetTextThickness( layer );
|
|
|
|
InferBold( &textAttrs );
|
|
|
|
textAttrs.m_Italic = bds.GetTextItalic( layer );
|
|
|
|
textAttrs.m_KeepUpright = bds.GetTextUpright( layer );
|
|
|
|
textAttrs.m_Mirrored = IsBackLayer( layer );
|
2022-06-20 11:46:03 +00:00
|
|
|
textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
textAttrs.m_Valign = GR_TEXT_V_ALIGN_BOTTOM;
|
2021-12-31 14:07:24 +00:00
|
|
|
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor )
|
2023-06-06 17:30:03 +00:00
|
|
|
text = new PCB_TEXT( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
else
|
2023-03-30 11:49:23 +00:00
|
|
|
text = new PCB_TEXT( m_frame->GetModel() );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
text->SetLayer( layer );
|
|
|
|
text->SetAttributes( textAttrs );
|
|
|
|
text->SetTextPos( cursorPos );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES textDialog( m_frame, text );
|
|
|
|
bool cancelled;
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
RunMainStack( [&]()
|
|
|
|
{
|
2023-05-24 11:08:52 +00:00
|
|
|
// QuasiModal required for Scintilla auto-complete
|
|
|
|
cancelled = !textDialog.ShowQuasiModal();
|
2023-03-30 11:49:23 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( cancelled || NoPrintableChars( text->GetText() ) )
|
|
|
|
{
|
|
|
|
delete text;
|
|
|
|
text = nullptr;
|
|
|
|
}
|
|
|
|
else if( text->GetTextPos() != 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
|
|
|
}
|
|
|
|
|
2019-08-01 05:09:55 +00:00
|
|
|
if( text )
|
|
|
|
{
|
2021-04-07 14:01:59 +00:00
|
|
|
if( !m_view->IsLayerVisible( text->GetLayer() ) )
|
|
|
|
{
|
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( text->GetLayer(), true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, text );
|
2020-05-09 13:10:08 +00:00
|
|
|
m_view->Update( &selection() );
|
2020-10-08 02:47:01 +00:00
|
|
|
|
|
|
|
// update the cursor so it looks correct before another event
|
|
|
|
setCursor();
|
2019-08-01 05:09:55 +00:00
|
|
|
}
|
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();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Add( text );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Place Text" ) );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, text );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
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 );
|
2021-12-07 17:27:17 +00:00
|
|
|
|
2022-05-16 22:41:30 +00:00
|
|
|
// If we started with a hotkey which has a position then warp back to that.
|
|
|
|
// Otherwise update to the current mouse position pinned inside the autoscroll
|
|
|
|
// boundaries.
|
|
|
|
if( evt->IsPrime() && !ignorePrimePosition )
|
|
|
|
{
|
|
|
|
cursorPos = evt->Position();
|
|
|
|
m_controls->WarpMouseCursor( cursorPos, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_controls->PinCursorInsideNonAutoscrollArea( true );
|
|
|
|
cursorPos = m_controls->GetMousePosition();
|
|
|
|
}
|
2021-12-07 17:27:17 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( PCB_ACTIONS::refreshPreview );
|
2021-12-07 17:27:17 +00:00
|
|
|
|
2019-08-01 05:09:55 +00:00
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->CaptureCursor( text != nullptr );
|
|
|
|
m_controls->SetAutoPan( text != nullptr );
|
2016-06-08 09:24:46 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( text && ( evt->IsMotion()
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::refreshPreview ) ) )
|
2016-06-08 09:24:46 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
text->SetPosition( cursorPos );
|
2019-05-19 21:04:04 +00:00
|
|
|
selection().SetReferencePoint( cursorPos );
|
|
|
|
m_view->Update( &selection() );
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( text && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2022-11-14 23:39:08 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( text && evt->IsAction( &PCB_ACTIONS::properties ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
frame()->OnEditItemRequest( text );
|
|
|
|
m_view->Update( &selection() );
|
|
|
|
frame()->SetMsgPanel( text );
|
2023-06-16 20:44:16 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2014-02-10 09:58:58 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
|
|
|
if( selection().Empty() )
|
|
|
|
m_frame->SetMsgPanel( board() );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2014-02-10 09:58:58 +00:00
|
|
|
return 0;
|
2014-02-10 14:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
void DRAWING_TOOL::constrainDimension( PCB_DIMENSION_BASE* aDim )
|
2018-06-03 04:01:01 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
const VECTOR2I lineVector{ aDim->GetEnd() - aDim->GetStart() };
|
2018-06-03 04:01:01 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
aDim->SetEnd( aDim->GetStart() + GetVectorSnapped45( lineVector ) );
|
2021-01-19 16:08:37 +00:00
|
|
|
aDim->Update();
|
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
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2018-05-14 03:22:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2021-04-07 13:50:18 +00:00
|
|
|
enum DIMENSION_STEPS
|
|
|
|
{
|
|
|
|
SET_ORIGIN = 0,
|
|
|
|
SET_END,
|
|
|
|
SET_HEIGHT,
|
|
|
|
FINISHED
|
|
|
|
};
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2021-04-07 13:50:18 +00:00
|
|
|
TOOL_EVENT originalEvent = aEvent;
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIMENSION_BASE* dimension = nullptr;
|
2021-04-07 13:50:18 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
|
|
|
BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
|
|
|
|
PCB_SELECTION preview; // A VIEW_GROUP that serves as a preview for the new item(s)
|
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
|
|
|
|
int step = SET_ORIGIN;
|
2021-12-04 23:52:00 +00:00
|
|
|
KICAD_T t = PCB_DIMENSION_T;
|
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
|
|
|
|
2021-04-07 13:50:18 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-04-07 13:50:18 +00:00
|
|
|
|
|
|
|
preview.Clear();
|
|
|
|
m_view->Update( &preview );
|
|
|
|
|
|
|
|
delete dimension;
|
|
|
|
dimension = nullptr;
|
|
|
|
step = SET_ORIGIN;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
|
|
|
|
};
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2014-02-11 13:38:44 +00:00
|
|
|
Activate();
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
m_controls->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2019-07-11 08:48:11 +00:00
|
|
|
|
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
|
|
|
{
|
2020-11-05 15:05:52 +00:00
|
|
|
if( step > SET_ORIGIN )
|
|
|
|
frame()->SetMsgPanel( dimension );
|
|
|
|
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2018-10-06 16:50:43 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-03-04 01:09:24 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( step == SET_HEIGHT && t != PCB_DIM_ORTHOGONAL_T )
|
2022-02-22 21:00:48 +00:00
|
|
|
{
|
|
|
|
if( dimension->GetStart().x != dimension->GetEnd().x
|
|
|
|
&& dimension->GetStart().y != dimension->GetEnd().y )
|
|
|
|
{
|
|
|
|
// Not cardinal. Grid snapping doesn't make sense for height.
|
|
|
|
grid.SetUseGrid( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:09:24 +00:00
|
|
|
VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
|
2021-12-11 23:57:51 +00:00
|
|
|
cursorPos = GetClampedCoords( grid.BestSnapAnchor( cursorPos, nullptr ), COORDS_PADDING );
|
2021-03-04 01:09:24 +00:00
|
|
|
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2018-10-06 16:50:43 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( dimension && evt->IsAction( &ACTIONS::undo ) ) )
|
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
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2014-02-19 12:51:32 +00:00
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() + WIDTH_STEP );
|
|
|
|
dimension->SetLineThickness( m_stroke.GetWidth() );
|
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
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
if( (unsigned) m_stroke.GetWidth() > WIDTH_STEP )
|
2014-09-01 11:48:51 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() - WIDTH_STEP );
|
|
|
|
dimension->SetLineThickness( m_stroke.GetWidth() );
|
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
|
|
|
}
|
2022-06-15 17:06:34 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2014-02-11 13:38:44 +00:00
|
|
|
{
|
|
|
|
switch( step )
|
|
|
|
{
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_ORIGIN:
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2020-06-27 21:08:13 +00:00
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
// Init the new item attributes
|
2020-09-22 02:32:40 +00:00
|
|
|
auto setMeasurementAttributes =
|
2021-06-11 16:59:28 +00:00
|
|
|
[&]( PCB_DIMENSION_BASE* aDim )
|
2020-09-22 02:32:40 +00:00
|
|
|
{
|
|
|
|
aDim->SetUnitsMode( boardSettings.m_DimensionUnitsMode );
|
|
|
|
aDim->SetUnitsFormat( boardSettings.m_DimensionUnitsFormat );
|
|
|
|
aDim->SetPrecision( boardSettings.m_DimensionPrecision );
|
|
|
|
aDim->SetSuppressZeroes( boardSettings.m_DimensionSuppressZeroes );
|
|
|
|
aDim->SetTextPositionMode( boardSettings.m_DimensionTextPosition );
|
|
|
|
aDim->SetKeepTextAligned( boardSettings.m_DimensionKeepTextAligned );
|
|
|
|
};
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dimension = new PCB_DIM_ALIGNED( m_frame->GetModel() );
|
2020-09-22 02:32:40 +00:00
|
|
|
setMeasurementAttributes( dimension );
|
|
|
|
}
|
|
|
|
else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dimension = new PCB_DIM_ORTHOGONAL( m_frame->GetModel() );
|
2020-09-22 02:32:40 +00:00
|
|
|
setMeasurementAttributes( dimension );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
2020-09-17 00:54:58 +00:00
|
|
|
else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dimension = new PCB_DIM_CENTER( m_frame->GetModel() );
|
2020-09-17 00:54:58 +00:00
|
|
|
}
|
2021-07-13 18:46:33 +00:00
|
|
|
else if( originalEvent.IsAction( &PCB_ACTIONS::drawRadialDimension ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dimension = new PCB_DIM_RADIAL( m_frame->GetModel() );
|
2021-07-13 18:46:33 +00:00
|
|
|
setMeasurementAttributes( dimension );
|
|
|
|
}
|
2020-09-12 20:09:40 +00:00
|
|
|
else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dimension = new PCB_DIM_LEADER( m_frame->GetModel() );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( cursorPos );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unhandled action in DRAWING_TOOL::DrawDimension" ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 23:52:00 +00:00
|
|
|
t = dimension->Type();
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
dimension->SetLayer( layer );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextSize( boardSettings.GetTextSize( layer ) );
|
|
|
|
dimension->SetTextThickness( boardSettings.GetTextThickness( layer ) );
|
|
|
|
dimension->SetItalic( boardSettings.GetTextItalic( layer ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
|
2020-09-12 00:36:43 +00:00
|
|
|
dimension->SetArrowLength( boardSettings.m_DimensionArrowLength );
|
2020-09-12 15:46:33 +00:00
|
|
|
dimension->SetExtensionOffset( boardSettings.m_DimensionExtensionOffset );
|
2022-01-30 10:52:52 +00:00
|
|
|
dimension->SetStart( cursorPos );
|
|
|
|
dimension->SetEnd( cursorPos );
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2021-04-07 14:01:59 +00:00
|
|
|
if( !m_view->IsLayerVisible( layer ) )
|
|
|
|
{
|
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
preview.Add( dimension );
|
2020-11-05 15:05:52 +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 );
|
2020-11-06 13:21:03 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2014-02-14 14:13:42 +00:00
|
|
|
case SET_END:
|
|
|
|
// Dimensions that have origin and end in the same spot are not valid
|
2020-09-09 03:17:08 +00:00
|
|
|
if( dimension->GetStart() == dimension->GetEnd() )
|
2021-07-13 18:46:33 +00:00
|
|
|
{
|
2014-02-14 14:13:42 +00:00
|
|
|
--step;
|
2021-07-13 18:46:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( t == PCB_DIM_CENTER_T || t == PCB_DIM_RADIAL_T || t == PCB_DIM_LEADER_T )
|
2020-09-17 00:54:58 +00:00
|
|
|
{
|
2021-07-13 18:46:33 +00:00
|
|
|
// No separate height step
|
2020-09-17 00:54:58 +00:00
|
|
|
++step;
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
}
|
|
|
|
else
|
2020-11-06 13:21:03 +00:00
|
|
|
{
|
2020-09-17 00:54:58 +00:00
|
|
|
break;
|
2020-11-06 13:21:03 +00:00
|
|
|
}
|
2014-02-14 14:13:42 +00:00
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_HEIGHT:
|
2021-07-13 18:46:33 +00:00
|
|
|
assert( dimension->GetStart() != dimension->GetEnd() );
|
|
|
|
assert( dimension->GetLineThickness() > 0 );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
preview.Remove( dimension );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
commit.Add( dimension );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Draw Dimension" ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2023-06-16 20:31:03 +00:00
|
|
|
// Run the edit immediately to set the leader text
|
2023-03-30 11:49:23 +00:00
|
|
|
if( t == PCB_DIM_LEADER_T )
|
2023-06-16 20:31:03 +00:00
|
|
|
frame()->OnEditItemRequest( dimension );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, dimension );
|
2020-09-17 00:54:58 +00:00
|
|
|
|
|
|
|
break;
|
2017-05-04 22:43:43 +00:00
|
|
|
}
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2022-06-15 17:06:34 +00:00
|
|
|
if( ++step >= FINISHED )
|
2014-02-19 12:51:32 +00:00
|
|
|
{
|
2022-07-21 12:19:40 +00:00
|
|
|
dimension = nullptr;
|
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
|
|
|
}
|
2022-06-15 17:06:34 +00:00
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( PCB_ACTIONS::cursorClick );
|
2022-06-15 17:06:34 +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:
|
2022-01-30 10:52:52 +00:00
|
|
|
dimension->SetEnd( cursorPos );
|
2021-03-05 14:40:02 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( Is45Limited() || t == PCB_DIM_CENTER_T )
|
2021-07-13 18:46:33 +00:00
|
|
|
constrainDimension( dimension );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( t == PCB_DIM_ORTHOGONAL_T )
|
2021-03-05 14:40:02 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
|
2021-03-05 14:40:02 +00:00
|
|
|
|
|
|
|
BOX2I bounds( dimension->GetStart(),
|
|
|
|
dimension->GetEnd() - dimension->GetStart() );
|
|
|
|
|
|
|
|
// Create a nice preview by measuring the longer dimension
|
|
|
|
bool vert = bounds.GetWidth() < bounds.GetHeight();
|
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
|
|
|
|
: PCB_DIM_ORTHOGONAL::DIR::HORIZONTAL );
|
2021-03-05 14:40:02 +00:00
|
|
|
}
|
2023-03-30 11:49:23 +00:00
|
|
|
else if( t == PCB_DIM_RADIAL_T )
|
2021-07-13 18:46:33 +00:00
|
|
|
{
|
|
|
|
PCB_DIM_RADIAL* radialDim = static_cast<PCB_DIM_RADIAL*>( dimension );
|
2022-01-30 10:52:52 +00:00
|
|
|
VECTOR2I textOffset( radialDim->GetArrowLength() * 10, 0 );
|
2021-03-05 14:40:02 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
if( radialDim->GetEnd().x < radialDim->GetStart().x )
|
|
|
|
textOffset = -textOffset;
|
2018-06-03 04:01:01 +00:00
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
radialDim->SetTextPos( radialDim->GetKnee() + textOffset );
|
2021-07-13 18:46:33 +00:00
|
|
|
}
|
2023-03-30 11:49:23 +00:00
|
|
|
else if( t == PCB_DIM_LEADER_T )
|
2021-07-13 18:46:33 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
VECTOR2I textOffset( dimension->GetArrowLength() * 10, 0 );
|
2021-07-13 18:46:33 +00:00
|
|
|
|
|
|
|
if( dimension->GetEnd().x < dimension->GetStart().x )
|
|
|
|
textOffset = -textOffset;
|
|
|
|
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( dimension->GetEnd() + textOffset );
|
2021-07-13 18:46:33 +00:00
|
|
|
}
|
2018-06-03 04:01:01 +00:00
|
|
|
|
2021-12-26 17:30:21 +00:00
|
|
|
dimension->Update();
|
2014-02-11 13:38:44 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-14 10:35:48 +00:00
|
|
|
case SET_HEIGHT:
|
2023-03-30 11:49:23 +00:00
|
|
|
if( t == PCB_DIM_ALIGNED_T )
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ALIGNED* aligned = static_cast<PCB_DIM_ALIGNED*>( dimension );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
// Calculating the direction of travel perpendicular to the selected axis
|
|
|
|
double angle = aligned->GetAngle() + ( M_PI / 2 );
|
2014-02-11 13:38:44 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I delta( (VECTOR2I) cursorPos - dimension->GetEnd() );
|
2020-09-12 20:09:40 +00:00
|
|
|
double height = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
|
|
|
|
aligned->SetHeight( height );
|
2021-01-19 16:08:37 +00:00
|
|
|
aligned->Update();
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
2023-03-30 11:49:23 +00:00
|
|
|
else if( t == PCB_DIM_ORTHOGONAL_T )
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
BOX2I bbox( dimension->GetStart(),
|
|
|
|
dimension->GetEnd() - dimension->GetStart() );
|
|
|
|
VECTOR2I direction( cursorPos - bbox.Centre() );
|
2021-03-05 14:40:02 +00:00
|
|
|
bool vert;
|
2020-09-22 02:32:40 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
// Only change the orientation when we move outside the bbox
|
|
|
|
if( !bbox.Contains( cursorPos ) )
|
2020-09-22 02:32:40 +00:00
|
|
|
{
|
2021-03-05 14:40:02 +00:00
|
|
|
// If the dimension is horizontal or vertical, set correct orientation
|
|
|
|
// otherwise, test if we're left/right of the bounding box or above/below it
|
2021-07-13 18:46:33 +00:00
|
|
|
if( bbox.GetWidth() == 0 )
|
2021-03-05 14:40:02 +00:00
|
|
|
vert = true;
|
2021-07-13 18:46:33 +00:00
|
|
|
else if( bbox.GetHeight() == 0 )
|
2021-03-05 14:40:02 +00:00
|
|
|
vert = false;
|
2021-07-13 18:46:33 +00:00
|
|
|
else if( cursorPos.x > bbox.GetLeft() && cursorPos.x < bbox.GetRight() )
|
2021-03-05 14:40:02 +00:00
|
|
|
vert = false;
|
2021-07-13 18:46:33 +00:00
|
|
|
else if( cursorPos.y > bbox.GetTop() && cursorPos.y < bbox.GetBottom() )
|
2021-03-05 14:40:02 +00:00
|
|
|
vert = true;
|
|
|
|
else
|
|
|
|
vert = std::abs( direction.y ) < std::abs( direction.x );
|
2021-07-13 18:46:33 +00:00
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
|
|
|
|
: PCB_DIM_ORTHOGONAL::DIR::HORIZONTAL );
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
vert = ortho->GetOrientation() == PCB_DIM_ORTHOGONAL::DIR::VERTICAL;
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I heightVector( cursorPos - dimension->GetStart() );
|
|
|
|
ortho->SetHeight( vert ? heightVector.x : heightVector.y );
|
2021-01-19 16:08:37 +00:00
|
|
|
ortho->Update();
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
2021-07-13 18:46:33 +00:00
|
|
|
|
|
|
|
break;
|
2014-02-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( dimension && evt->IsAction( &PCB_ACTIONS::layerChanged ) )
|
2021-04-07 14:01:59 +00:00
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
2021-04-07 14:01:59 +00:00
|
|
|
|
2022-11-14 23:39:08 +00:00
|
|
|
if( !m_view->IsLayerVisible( layer ) )
|
2021-04-07 14:01:59 +00:00
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2021-04-07 14:01:59 +00:00
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
|
|
|
|
dimension->SetLayer( layer );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextSize( boardSettings.GetTextSize( layer ) );
|
|
|
|
dimension->SetTextThickness( boardSettings.GetTextThickness( layer ) );
|
|
|
|
dimension->SetItalic( boardSettings.GetTextItalic( layer ) );
|
2022-11-14 23:39:08 +00:00
|
|
|
dimension->SetLineThickness( boardSettings.GetLineThickness( layer ) );
|
|
|
|
dimension->Update();
|
|
|
|
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( dimension );
|
2021-04-07 14:01:59 +00:00
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( dimension && evt->IsAction( &PCB_ACTIONS::properties ) )
|
2020-09-17 21:29:40 +00:00
|
|
|
{
|
2020-11-06 13:21:03 +00:00
|
|
|
if( step == SET_END || step == SET_HEIGHT )
|
2020-09-17 21:29:40 +00:00
|
|
|
{
|
|
|
|
frame()->OnEditItemRequest( dimension );
|
|
|
|
dimension->Update();
|
|
|
|
frame()->SetMsgPanel( dimension );
|
2020-11-06 13:21:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
wxBell();
|
2020-09-17 21:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( dimension && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
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 );
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2018-08-06 08:15:58 +00:00
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
|
|
|
if( selection().Empty() )
|
|
|
|
m_frame->SetMsgPanel( board() );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
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;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
// Note: PlaceImportedGraphics() will convert PCB_SHAPE_T and PCB_TEXT_T to footprint
|
2019-05-31 23:24:38 +00:00
|
|
|
// items if needed
|
2020-11-07 17:50:22 +00:00
|
|
|
DIALOG_IMPORT_GFX dlg( m_frame, m_isFootprintEditor );
|
2014-07-09 13:02:56 +00:00
|
|
|
int dlgResult = dlg.ShowModal();
|
|
|
|
|
2020-08-20 00:22:48 +00:00
|
|
|
std::list<std::unique_ptr<EDA_ITEM>>& 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() )
|
|
|
|
{
|
2021-06-22 11:52:40 +00:00
|
|
|
wxMessageBox( _( "No graphic items found in file.") );
|
2018-11-05 16:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
std::vector<BOARD_ITEM*> newItems; // all new items, including group
|
|
|
|
std::vector<BOARD_ITEM*> selectedItems; // the group, or newItems if no group
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION preview;
|
2020-11-27 18:02:31 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
PCB_GROUP* group = nullptr;
|
2022-11-30 18:57:42 +00:00
|
|
|
PCB_LAYER_ID layer = F_Cu;
|
2020-08-20 00:22:48 +00:00
|
|
|
|
|
|
|
if( dlg.ShouldGroupItems() )
|
2020-10-26 23:52:53 +00:00
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor )
|
2020-11-27 18:02:31 +00:00
|
|
|
group = new PCB_GROUP( m_frame->GetBoard()->GetFirstFootprint() );
|
2020-10-26 23:52:53 +00:00
|
|
|
else
|
2020-11-27 18:02:31 +00:00
|
|
|
group = new PCB_GROUP( m_frame->GetBoard() );
|
|
|
|
|
|
|
|
newItems.push_back( group );
|
|
|
|
selectedItems.push_back( group );
|
|
|
|
preview.Add( group );
|
2020-10-26 23:52:53 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
for( std::unique_ptr<EDA_ITEM>& ptr : list )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( ptr.get() );
|
|
|
|
wxCHECK2( item, continue );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
newItems.push_back( item );
|
|
|
|
|
|
|
|
if( group )
|
|
|
|
group->AddItem( item );
|
2018-11-05 16:04:05 +00:00
|
|
|
else
|
2020-11-27 18:02:31 +00:00
|
|
|
selectedItems.push_back( item );
|
|
|
|
|
|
|
|
preview.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() )
|
|
|
|
{
|
2020-11-27 18:02:31 +00:00
|
|
|
for( BOARD_ITEM* item : newItems )
|
|
|
|
commit.Add( item );
|
2020-08-20 00:22:48 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Import Graphic" ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:57:42 +00:00
|
|
|
layer = newItems.front()->GetLayer();
|
|
|
|
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2020-08-20 00:22:48 +00:00
|
|
|
// Clear the current selection then select the drawings so that edit tools work on them
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2023-06-16 21:28:15 +00:00
|
|
|
|
|
|
|
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &selItems );
|
2020-08-20 00:22:48 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2014-07-09 13:02:56 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
|
2022-11-30 18:57:42 +00:00
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2018-07-07 11:04:01 +00:00
|
|
|
// Now move the new items to the current cursor position:
|
2022-11-30 14:37:46 +00:00
|
|
|
VECTOR2I cursorPos = m_controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2022-11-30 20:25:03 +00:00
|
|
|
VECTOR2I delta = cursorPos - static_cast<BOARD_ITEM*>( preview.GetTopLeftItem() )->GetPosition();
|
2018-07-07 11:04:01 +00:00
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
for( BOARD_ITEM* item : selectedItems )
|
2022-01-30 10:52:52 +00:00
|
|
|
item->Move( delta );
|
2018-07-07 11:04:01 +00:00
|
|
|
|
|
|
|
m_view->Update( &preview );
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
// 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
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2022-11-30 18:57:42 +00:00
|
|
|
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
|
|
|
cursorPos = GetClampedCoords(
|
|
|
|
grid.BestSnapAnchor( m_controls->GetMousePosition(), layer ),
|
|
|
|
COORDS_PADDING );
|
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2019-07-09 23:51:47 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2020-08-20 00:22:48 +00:00
|
|
|
|
2022-11-24 00:20:12 +00:00
|
|
|
if( group )
|
|
|
|
{
|
|
|
|
preview.Remove( group );
|
|
|
|
group->RemoveAll();
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
for( BOARD_ITEM* item : newItems )
|
|
|
|
delete item;
|
2020-08-20 00:22:48 +00:00
|
|
|
|
2019-07-09 23:51:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2022-11-30 20:25:03 +00:00
|
|
|
delta = cursorPos - static_cast<BOARD_ITEM*>( preview.GetTopLeftItem() )->GetPosition();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2020-11-27 18:02:31 +00:00
|
|
|
for( BOARD_ITEM* item : selectedItems )
|
2022-01-30 10:52:52 +00:00
|
|
|
item->Move( 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
|
|
|
}
|
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
|
|
|
}
|
2020-12-14 22:03:17 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
// Place the imported drawings
|
2020-11-27 18:02:31 +00:00
|
|
|
for( BOARD_ITEM* item : newItems )
|
2018-11-05 16:04:05 +00:00
|
|
|
commit.Add( item );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Import Graphic" ) );
|
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
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( ZONE_FILLER_TOOL::IsZoneFillAction( evt ) )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preview.Clear();
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2020-11-19 20:08:58 +00:00
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
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
|
|
|
{
|
2023-02-09 15:29:33 +00:00
|
|
|
// Make sense only in FP editor
|
|
|
|
if( !m_isFootprintEditor )
|
|
|
|
return 0;
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2018-05-14 03:22:11 +00:00
|
|
|
if( !m_frame->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2021-06-20 10:02:44 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
2021-07-27 15:36:46 +00:00
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
|
2021-03-12 17:37:09 +00:00
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
m_controls->ShowCursor( true );
|
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2020-10-08 00:50:28 +00:00
|
|
|
// Set initial cursor
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-06-08 17:23:38 +00:00
|
|
|
|
2019-08-28 04:38:27 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-11-04 14:08:06 +00:00
|
|
|
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(),
|
|
|
|
LSET::AllLayersMask() );
|
2019-08-28 04:38:27 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
2020-12-14 22:03:17 +00:00
|
|
|
if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = (FOOTPRINT*) m_frame->GetModel();
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2020-11-13 15:15:52 +00:00
|
|
|
commit.Modify( footprint );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
// set the new relative internal local coordinates of footprint items
|
2022-01-30 10:52:52 +00:00
|
|
|
VECTOR2I moveVector = footprint->GetPosition() - cursorPos;
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->MoveAnchorPosition( moveVector );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Move Footprint 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
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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() )
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-06-20 10:02:44 +00:00
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-29 13:16:13 +00:00
|
|
|
int DRAWING_TOOL::ToggleHV45Mode( const TOOL_EVENT& toolEvent )
|
2021-02-05 23:43:32 +00:00
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
#define TOGGLE( a ) a = !a
|
|
|
|
|
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
|
|
|
|
if( frame()->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
TOGGLE( mgr.GetAppSettings<PCBNEW_SETTINGS>()->m_Use45DegreeLimit );
|
2021-10-01 11:11:03 +00:00
|
|
|
else
|
2021-08-29 23:33:08 +00:00
|
|
|
TOGGLE( mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>()->m_Use45Limit );
|
2021-02-05 23:43:32 +00:00
|
|
|
|
2022-07-27 12:37:20 +00:00
|
|
|
UpdateStatusBar();
|
2021-10-24 12:15:53 +00:00
|
|
|
|
2021-02-05 23:43:32 +00:00
|
|
|
return 0;
|
2021-08-29 23:33:08 +00:00
|
|
|
|
|
|
|
#undef TOGGLE
|
2021-02-05 23:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 15:05:17 +00:00
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* Update a #PCB_SHAPE from the current state of a #TWO_POINT_GEOMETRY_MANAGER.
|
2020-07-03 15:05:17 +00:00
|
|
|
*/
|
2020-11-04 14:08:06 +00:00
|
|
|
static void updateSegmentFromGeometryMgr( const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER& aMgr,
|
|
|
|
PCB_SHAPE* aGraphic )
|
2020-07-03 15:05:17 +00:00
|
|
|
{
|
2020-11-05 15:05:52 +00:00
|
|
|
if( !aMgr.IsReset() )
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
aGraphic->SetStart( aMgr.GetOrigin() );
|
|
|
|
aGraphic->SetEnd( aMgr.GetEnd() );
|
2020-11-05 15:05:52 +00:00
|
|
|
}
|
2020-07-03 15:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
|
2023-06-19 16:09:03 +00:00
|
|
|
std::optional<VECTOR2D> aStartingPoint,
|
|
|
|
std::stack<PCB_SHAPE*>* aCommittedGraphics )
|
2014-02-11 16:15:33 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
SHAPE_T shape = ( *aGraphic )->GetShape();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
// Only three shapes are currently supported
|
2023-07-24 16:07:56 +00:00
|
|
|
wxASSERT( shape == SHAPE_T::SEGMENT || shape == SHAPE_T::CIRCLE || shape == SHAPE_T::RECTANGLE );
|
2020-11-05 15:05:52 +00:00
|
|
|
|
2022-06-03 17:47:03 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings();
|
|
|
|
EDA_UNITS userUnits = m_frame->GetUserUnits();
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
|
|
|
PCB_SHAPE*& graphic = *aGraphic;
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
if( m_layer != m_frame->GetActiveLayer() )
|
|
|
|
{
|
|
|
|
m_layer = m_frame->GetActiveLayer();
|
2023-06-13 10:05:16 +00:00
|
|
|
m_stroke.SetWidth( bds.GetLineThickness( m_layer ) );
|
2021-10-22 16:00:55 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
2022-06-03 17:47:03 +00:00
|
|
|
|
|
|
|
m_textAttrs.m_Size = bds.GetTextSize( m_layer );
|
|
|
|
m_textAttrs.m_StrokeWidth = bds.GetTextThickness( m_layer );
|
|
|
|
InferBold( &m_textAttrs );
|
|
|
|
m_textAttrs.m_Italic = bds.GetTextItalic( m_layer );
|
|
|
|
m_textAttrs.m_KeepUpright = bds.GetTextUpright( m_layer );
|
|
|
|
m_textAttrs.m_Mirrored = IsBackLayer( m_layer );
|
2022-06-20 11:46:03 +00:00
|
|
|
m_textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
m_textAttrs.m_Valign = GR_TEXT_V_ALIGN_TOP;
|
2021-10-22 16:00:55 +00:00
|
|
|
}
|
2018-10-03 12:57:02 +00:00
|
|
|
|
2020-07-03 15:05:17 +00:00
|
|
|
// geometric construction manager
|
2023-07-15 16:37:17 +00:00
|
|
|
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPointMgr;
|
2020-07-03 15:05:17 +00:00
|
|
|
|
|
|
|
// drawing assistant overlay
|
2021-07-14 20:03:32 +00:00
|
|
|
// TODO: workaround because EDA_SHAPE_TYPE_T is not visible from commons.
|
2020-11-05 15:05:52 +00:00
|
|
|
KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( shape ) );
|
2023-07-15 16:37:17 +00:00
|
|
|
KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointMgr, pcbIUScale, userUnits, geomShape );
|
2020-07-03 15:05:17 +00:00
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION preview;
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Add( &preview );
|
2020-07-03 15:05:17 +00:00
|
|
|
m_view->Add( &twoPointAsst );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
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
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
2020-10-06 09:57:30 +00:00
|
|
|
|
2021-04-05 22:29:12 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
m_view->Update( &preview );
|
|
|
|
delete graphic;
|
|
|
|
graphic = nullptr;
|
|
|
|
|
|
|
|
if( !isLocalOriginSet )
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2021-04-05 22:29:12 +00:00
|
|
|
|
|
|
|
if( aStartingPoint )
|
2022-08-30 20:58:43 +00:00
|
|
|
m_toolMgr->PrimeTool( *aStartingPoint );
|
2021-04-05 22:29:12 +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
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-11-05 15:05:52 +00:00
|
|
|
|
|
|
|
if( started )
|
|
|
|
m_frame->SetMsgPanel( graphic );
|
2020-09-15 18:21:10 +00:00
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-12-11 23:57:51 +00:00
|
|
|
cursorPos = GetClampedCoords(
|
|
|
|
grid.BestSnapAnchor( m_controls->GetMousePosition(), m_layer ),
|
|
|
|
COORDS_PADDING );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-02-11 16:15:33 +00:00
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
2014-02-14 14:13:42 +00:00
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( !started )
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2021-05-25 23:45:57 +00:00
|
|
|
// We've handled the cancel event. Don't cancel other tools
|
|
|
|
evt->SetPassEvent( false );
|
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() )
|
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
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
|
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
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
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
if( m_layer != m_frame->GetActiveLayer() )
|
|
|
|
{
|
|
|
|
m_layer = m_frame->GetActiveLayer();
|
2023-06-13 10:05:16 +00:00
|
|
|
m_stroke.SetWidth( bds.GetLineThickness( m_layer ) );
|
2021-10-22 16:00:55 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
2022-06-03 17:47:03 +00:00
|
|
|
|
|
|
|
m_textAttrs.m_Size = bds.GetTextSize( m_layer );
|
|
|
|
m_textAttrs.m_StrokeWidth = bds.GetTextThickness( m_layer );
|
|
|
|
InferBold( &m_textAttrs );
|
|
|
|
m_textAttrs.m_Italic = bds.GetTextItalic( m_layer );
|
|
|
|
m_textAttrs.m_KeepUpright = bds.GetTextUpright( m_layer );
|
|
|
|
m_textAttrs.m_Mirrored = IsBackLayer( m_layer );
|
2022-06-20 11:46:03 +00:00
|
|
|
m_textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
m_textAttrs.m_Valign = GR_TEXT_V_ALIGN_TOP;
|
2021-10-22 16:00:55 +00:00
|
|
|
}
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2021-04-07 14:01:59 +00:00
|
|
|
if( graphic )
|
2021-04-05 22:29:12 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
if( !m_view->IsLayerVisible( m_layer ) )
|
2021-04-07 14:01:59 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( m_layer, true );
|
2021-04-07 14:01:59 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
graphic->SetLayer( m_layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
graphic->SetStroke( m_stroke );
|
2022-06-03 17:47:03 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( PCB_TEXTBOX* pcb_textbox = dynamic_cast<PCB_TEXTBOX*>( graphic ) )
|
2022-06-03 17:47:03 +00:00
|
|
|
pcb_textbox->SetAttributes( m_textAttrs );
|
|
|
|
|
2021-04-07 14:01:59 +00:00
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
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
|
|
|
{
|
2022-08-26 15:30:54 +00:00
|
|
|
if( !graphic )
|
|
|
|
break;
|
|
|
|
|
2014-07-09 12:01:06 +00:00
|
|
|
if( !started )
|
2014-02-14 09:47:43 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
if( aStartingPoint )
|
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
cursorPos = *aStartingPoint;
|
2022-08-25 22:50:47 +00:00
|
|
|
aStartingPoint = std::nullopt;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
// Init the new item attributes
|
2022-08-26 15:30:54 +00:00
|
|
|
if( graphic ) // always true, but Coverity can't seem to figure that out
|
|
|
|
{
|
|
|
|
graphic->SetShape( static_cast<SHAPE_T>( shape ) );
|
|
|
|
graphic->SetFilled( false );
|
|
|
|
graphic->SetStroke( m_stroke );
|
|
|
|
graphic->SetLayer( m_layer );
|
|
|
|
}
|
2022-06-03 17:47:03 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( PCB_TEXTBOX* pcb_textbox = dynamic_cast<PCB_TEXTBOX*>( graphic ) )
|
2022-06-03 17:47:03 +00:00
|
|
|
pcb_textbox->SetAttributes( m_textAttrs );
|
|
|
|
|
2020-01-19 04:42:10 +00:00
|
|
|
grid.SetSkipPoint( cursorPos );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
twoPointMgr.SetOrigin( cursorPos );
|
|
|
|
twoPointMgr.SetEnd( cursorPos );
|
2020-07-03 15:05:17 +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
|
|
|
|
2020-06-16 09:47:07 +00:00
|
|
|
preview.Add( graphic );
|
2020-11-05 15:05:52 +00:00
|
|
|
frame()->SetMsgPanel( graphic );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
if( !m_view->IsLayerVisible( m_layer ) )
|
2021-04-05 22:29:12 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( m_layer, true );
|
2021-04-05 22:29:12 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
updateSegmentFromGeometryMgr( twoPointMgr, graphic );
|
2020-07-03 15:05:17 +00:00
|
|
|
|
2017-02-08 09:13:43 +00:00
|
|
|
started = true;
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-24 18:54:50 +00:00
|
|
|
PCB_SHAPE* snapItem = dynamic_cast<PCB_SHAPE*>( grid.GetSnapped() );
|
2018-11-24 15:58:33 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( shape == SHAPE_T::SEGMENT && ( twoPointMgr.GetOrigin() == twoPointMgr.GetEnd()
|
|
|
|
|| evt->IsDblClick( BUT_LEFT )
|
|
|
|
|| snapItem ) )
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
// User has clicked twice in the same spot
|
|
|
|
// or clicked on the end of an existing segment (closing a path)
|
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
|
2023-07-15 16:37:17 +00:00
|
|
|
if( snapItem && graphic->GetLength() > 0.0 )
|
2018-11-24 15:58:33 +00:00
|
|
|
{
|
2020-06-16 09:47:07 +00:00
|
|
|
commit.Add( graphic );
|
2023-07-15 16:37:17 +00:00
|
|
|
commit.Push( _( "Draw Line" ) );
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, graphic );
|
2019-06-27 11:47:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-16 09:47:07 +00:00
|
|
|
delete graphic;
|
2015-07-03 18:58:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 09:47:07 +00:00
|
|
|
graphic = nullptr;
|
2015-07-03 18:58:13 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
preview.Clear();
|
2023-07-15 16:37:17 +00:00
|
|
|
twoPointMgr.Reset();
|
2014-07-09 12:01:06 +00:00
|
|
|
break;
|
2014-02-14 09:47:43 +00:00
|
|
|
}
|
2020-07-03 15:05:17 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
twoPointMgr.SetEnd( GetClampedCoords( cursorPos ) );
|
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
|
|
|
{
|
2021-12-11 23:57:51 +00:00
|
|
|
VECTOR2I clampedCursorPos = cursorPos;
|
|
|
|
|
|
|
|
if( shape == SHAPE_T::CIRCLE || shape == SHAPE_T::ARC )
|
2023-07-15 16:37:17 +00:00
|
|
|
clampedCursorPos = getClampedRadiusEnd( twoPointMgr.GetOrigin(), cursorPos );
|
2021-12-11 23:57:51 +00:00
|
|
|
else
|
2023-07-15 16:37:17 +00:00
|
|
|
clampedCursorPos = getClampedDifferenceEnd( twoPointMgr.GetOrigin(), cursorPos );
|
2021-12-11 23:57:51 +00:00
|
|
|
|
2014-02-14 09:47:43 +00:00
|
|
|
// 45 degree lines
|
2021-09-02 22:32:15 +00:00
|
|
|
if( started && Is45Limited() )
|
2018-12-08 06:07:53 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
const VECTOR2I lineVector( clampedCursorPos - VECTOR2I( twoPointMgr.GetOrigin() ) );
|
2018-12-08 06:07:53 +00:00
|
|
|
|
|
|
|
// get a restricted 45/H/V line from the last fixed point to the cursor
|
2023-07-24 16:07:56 +00:00
|
|
|
VECTOR2I newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECTANGLE ) );
|
2023-07-15 16:37:17 +00:00
|
|
|
m_controls->ForceCursorPosition( true, VECTOR2I( twoPointMgr.GetEnd() ) );
|
|
|
|
twoPointMgr.SetEnd( twoPointMgr.GetOrigin() + newEnd );
|
|
|
|
twoPointMgr.SetAngleSnap( true );
|
2018-12-08 06:07:53 +00:00
|
|
|
}
|
2014-02-14 09:47:43 +00:00
|
|
|
else
|
2020-07-03 15:05:17 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
twoPointMgr.SetEnd( clampedCursorPos );
|
|
|
|
twoPointMgr.SetAngleSnap( false );
|
2020-07-03 15:05:17 +00:00
|
|
|
}
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
updateSegmentFromGeometryMgr( twoPointMgr, graphic );
|
2017-02-08 09:13:43 +00:00
|
|
|
m_view->Update( &preview );
|
2020-07-03 15:05:17 +00:00
|
|
|
m_view->Update( &twoPointAsst );
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( evt->IsAction( &ACTIONS::undo )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::doDelete )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::deleteLastPoint ) ) )
|
2023-06-19 16:09:03 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( aCommittedGraphics && !aCommittedGraphics->empty() )
|
2023-06-19 16:09:03 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
twoPointMgr.SetOrigin( aCommittedGraphics->top()->GetStart() );
|
|
|
|
twoPointMgr.SetEnd( aCommittedGraphics->top()->GetEnd() );
|
2023-06-19 16:09:03 +00:00
|
|
|
aCommittedGraphics->pop();
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
getViewControls()->WarpMouseCursor( twoPointMgr.GetEnd(), true );
|
2023-06-19 16:09:03 +00:00
|
|
|
|
|
|
|
if( PICKED_ITEMS_LIST* undo = m_frame->PopCommandFromUndoList() )
|
|
|
|
{
|
|
|
|
m_frame->PutDataInPreviousState( undo );
|
|
|
|
m_frame->ClearListAndDeleteItems( undo );
|
|
|
|
delete undo;
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
updateSegmentFromGeometryMgr( twoPointMgr, graphic );
|
2023-06-19 16:09:03 +00:00
|
|
|
m_view->Update( &preview );
|
|
|
|
m_view->Update( &twoPointAsst );
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else
|
2023-06-19 16:09:03 +00:00
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( graphic && evt->IsAction( &PCB_ACTIONS::incWidth ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() + WIDTH_STEP );
|
|
|
|
graphic->SetStroke( m_stroke );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( graphic && evt->IsAction( &PCB_ACTIONS::decWidth ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
if( (unsigned) m_stroke.GetWidth() > WIDTH_STEP )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() - WIDTH_STEP );
|
|
|
|
graphic->SetStroke( m_stroke );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
}
|
2017-02-08 09:13:43 +00:00
|
|
|
}
|
2022-11-14 23:39:08 +00:00
|
|
|
else if( started && evt->IsAction( &PCB_ACTIONS::properties ) )
|
|
|
|
{
|
|
|
|
frame()->OnEditItemRequest( graphic );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
break;
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2022-11-14 23:39:08 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
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;
|
2020-10-06 09:57:30 +00:00
|
|
|
evt->SetPassEvent();
|
2017-12-21 20:49:52 +00:00
|
|
|
}
|
2020-11-04 14:08:06 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::updateUnits ) )
|
|
|
|
{
|
2020-11-05 15:05:52 +00:00
|
|
|
if( frame()->GetUserUnits() != userUnits )
|
|
|
|
{
|
|
|
|
userUnits = frame()->GetUserUnits();
|
|
|
|
twoPointAsst.SetUnits( userUnits );
|
|
|
|
m_view->Update( &twoPointAsst );
|
|
|
|
}
|
2020-11-04 14:08:06 +00:00
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2014-02-11 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
if( !isLocalOriginSet ) // reset the relative coordinate if it was not set before
|
2019-06-13 13:34:38 +00:00
|
|
|
m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 );
|
2017-12-21 20:49:52 +00:00
|
|
|
|
2020-07-03 15:05:17 +00:00
|
|
|
m_view->Remove( &twoPointAsst );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
|
|
|
if( selection().Empty() )
|
|
|
|
m_frame->SetMsgPanel( board() );
|
2020-11-19 20:08:58 +00:00
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
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
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* Update an arc PCB_SHAPE from the current state 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,
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE& aArc )
|
2017-02-26 20:08:45 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
VECTOR2I vec = aMgr.GetOrigin();
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
aArc.SetCenter( vec );
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2022-10-07 03:50:50 +00:00
|
|
|
if( aMgr.GetSubtended() < ANGLE_0 )
|
|
|
|
{
|
|
|
|
vec = aMgr.GetStartRadiusEnd();
|
|
|
|
aArc.SetStart( vec );
|
|
|
|
vec = aMgr.GetEndRadiusEnd();
|
|
|
|
aArc.SetEnd( vec );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vec = aMgr.GetEndRadiusEnd();
|
|
|
|
aArc.SetStart( vec );
|
|
|
|
vec = aMgr.GetStartRadiusEnd();
|
|
|
|
aArc.SetEnd( vec );
|
|
|
|
}
|
2017-02-26 20:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
bool DRAWING_TOOL::drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
|
2022-08-25 22:50:47 +00:00
|
|
|
std::optional<VECTOR2D> aStartingPoint )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2022-10-26 18:39:44 +00:00
|
|
|
wxCHECK( aGraphic, false );
|
|
|
|
|
2021-04-05 22:29:12 +00:00
|
|
|
PCB_SHAPE*& graphic = *aGraphic;
|
2022-10-26 18:39:44 +00:00
|
|
|
|
|
|
|
wxCHECK( graphic, false );
|
2021-11-13 16:38:19 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
if( m_layer != m_frame->GetActiveLayer() )
|
|
|
|
{
|
|
|
|
m_layer = m_frame->GetActiveLayer();
|
2023-06-13 10:05:16 +00:00
|
|
|
m_stroke.SetWidth( m_frame->GetDesignSettings().GetLineThickness( m_layer ) );
|
2021-10-22 16:00:55 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
|
|
|
}
|
2018-10-18 14:15:22 +00:00
|
|
|
|
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
|
2022-09-16 04:38:10 +00:00
|
|
|
KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, pcbIUScale, m_frame->GetUserUnits() );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_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 );
|
2021-01-16 23:17:32 +00:00
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
2021-04-05 22:29:12 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
preview.Clear();
|
|
|
|
delete *aGraphic;
|
|
|
|
*aGraphic = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
m_controls->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2022-11-14 23:39:08 +00:00
|
|
|
bool started = false;
|
2021-09-13 12:23:10 +00:00
|
|
|
bool cancelled = false;
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2022-05-16 09:22:55 +00:00
|
|
|
if( aStartingPoint )
|
2022-08-30 20:58:43 +00:00
|
|
|
m_toolMgr->PrimeTool( *aStartingPoint );
|
2021-04-05 22:29:12 +00:00
|
|
|
|
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
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
if( started )
|
2020-11-05 15:05:52 +00:00
|
|
|
m_frame->SetMsgPanel( graphic );
|
|
|
|
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-10-08 00:50:28 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
graphic->SetLayer( m_layer );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-12-11 23:57:51 +00:00
|
|
|
VECTOR2I cursorPos = GetClampedCoords(
|
|
|
|
grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic ), COORDS_PADDING );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2023-07-15 16:37:17 +00:00
|
|
|
if( evt->IsCancelInteractive() || ( started && evt->IsAction( &ACTIONS::undo ) ) )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
cleanup();
|
|
|
|
|
2022-11-14 23:39:08 +00:00
|
|
|
if( !started )
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2021-05-25 23:45:57 +00:00
|
|
|
// We've handled the cancel event. Don't cancel other tools
|
|
|
|
evt->SetPassEvent( false );
|
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() )
|
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
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
|
|
|
|
{
|
2020-04-16 20:57:07 +00:00
|
|
|
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
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
if( !started )
|
2014-07-09 12:01:06 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
|
|
|
|
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)
|
2021-07-21 18:31:25 +00:00
|
|
|
graphic->SetShape( SHAPE_T::ARC );
|
2021-07-17 19:56:18 +00:00
|
|
|
graphic->SetStroke( m_stroke );
|
2014-07-09 12:01:06 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
if( !m_view->IsLayerVisible( m_layer ) )
|
2021-04-05 22:29:12 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( m_layer, true );
|
2021-04-05 22:29:12 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
2020-06-16 09:47:07 +00:00
|
|
|
preview.Add( graphic );
|
2020-11-05 15:05:52 +00:00
|
|
|
frame()->SetMsgPanel( graphic );
|
2022-11-14 23:39:08 +00:00
|
|
|
started = 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
|
2021-09-02 22:32:15 +00:00
|
|
|
arcManager.SetAngleSnap( Is45Limited() );
|
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 ) )
|
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
if( m_layer != m_frame->GetActiveLayer() )
|
|
|
|
{
|
|
|
|
m_layer = m_frame->GetActiveLayer();
|
2023-06-13 10:05:16 +00:00
|
|
|
m_stroke.SetWidth( m_frame->GetDesignSettings().GetLineThickness( m_layer ) );
|
2021-10-22 16:00:55 +00:00
|
|
|
m_stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
m_stroke.SetColor( COLOR4D::UNSPECIFIED );
|
|
|
|
}
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2021-04-07 14:01:59 +00:00
|
|
|
if( graphic )
|
2021-04-05 22:29:12 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
if( !m_view->IsLayerVisible( m_layer ) )
|
2021-04-07 14:01:59 +00:00
|
|
|
{
|
2021-10-22 16:00:55 +00:00
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( m_layer, true );
|
2021-04-07 14:01:59 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2021-10-22 16:00:55 +00:00
|
|
|
graphic->SetLayer( m_layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
graphic->SetStroke( m_stroke );
|
2021-04-07 14:01:59 +00:00
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2018-10-07 04:38:37 +00:00
|
|
|
}
|
2020-09-17 21:29:40 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::properties ) )
|
|
|
|
{
|
2020-11-05 20:20:16 +00:00
|
|
|
if( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_START )
|
2020-09-17 21:29:40 +00:00
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
graphic->SetArcAngleAndEnd( ANGLE_90 );
|
2020-09-17 21:29:40 +00:00
|
|
|
frame()->OnEditItemRequest( graphic );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
2020-11-05 20:20:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-07 01:16:28 +00:00
|
|
|
// Don't show the edit panel if we can't represent the arc with it
|
|
|
|
else if( ( arcManager.GetStep() == KIGFX::PREVIEW::ARC_GEOM_MANAGER::SET_ANGLE )
|
|
|
|
&& ( arcManager.GetStartRadiusEnd() != arcManager.GetEndRadiusEnd() ) )
|
2020-11-05 20:20:16 +00:00
|
|
|
{
|
|
|
|
frame()->OnEditItemRequest( graphic );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
break;
|
2020-09-17 21:29:40 +00:00
|
|
|
}
|
2020-11-06 13:21:03 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2020-09-17 21:29:40 +00:00
|
|
|
}
|
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
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() + WIDTH_STEP );
|
2023-07-15 16:37:17 +00:00
|
|
|
|
|
|
|
if( graphic )
|
|
|
|
{
|
|
|
|
graphic->SetStroke( m_stroke );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
}
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
|
2014-08-04 12:23:19 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
if( (unsigned) m_stroke.GetWidth() > WIDTH_STEP )
|
|
|
|
{
|
|
|
|
m_stroke.SetWidth( m_stroke.GetWidth() - WIDTH_STEP );
|
2023-07-15 16:37:17 +00:00
|
|
|
|
|
|
|
if( graphic )
|
|
|
|
{
|
|
|
|
graphic->SetStroke( m_stroke );
|
|
|
|
m_view->Update( &preview );
|
|
|
|
frame()->SetMsgPanel( graphic );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|
2020-11-04 14:08:06 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::updateUnits ) )
|
|
|
|
{
|
|
|
|
arcAsst.SetUnits( frame()->GetUserUnits() );
|
|
|
|
m_view->Update( &arcAsst );
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2023-06-16 20:44:16 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2014-08-04 12:23:19 +00:00
|
|
|
|
2017-02-26 20:08:45 +00:00
|
|
|
if( arcManager.IsComplete() )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( arcManager.HasGeometryChanged() )
|
|
|
|
{
|
2020-06-16 09:47:07 +00:00
|
|
|
updateArcFromConstructionMgr( arcManager, *graphic );
|
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
|
|
|
|
2022-11-14 23:39:08 +00:00
|
|
|
if( started )
|
2020-06-16 09:47:07 +00:00
|
|
|
frame()->SetMsgPanel( graphic );
|
2018-04-12 16:33:18 +00:00
|
|
|
else
|
|
|
|
frame()->SetMsgPanel( board() );
|
2014-08-04 12:23:19 +00:00
|
|
|
}
|
2014-07-09 12:01:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 09:47:07 +00:00
|
|
|
preview.Remove( graphic );
|
2017-02-26 20:08:45 +00:00
|
|
|
m_view->Remove( &arcAsst );
|
2017-01-18 21:04:35 +00:00
|
|
|
m_view->Remove( &preview );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
|
|
|
if( selection().Empty() )
|
|
|
|
m_frame->SetMsgPanel( board() );
|
2020-11-19 20:08:58 +00:00
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool DRAWING_TOOL::getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone )
|
2017-02-06 05:59:55 +00:00
|
|
|
{
|
2018-08-28 21:49:48 +00:00
|
|
|
bool clearSelection = false;
|
2020-06-16 09:47:07 +00:00
|
|
|
*aZone = nullptr;
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const PCB_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;
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor );
|
2018-08-28 21:49:48 +00:00
|
|
|
}
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
// we want a single zone
|
2023-06-24 18:54:50 +00:00
|
|
|
if( selection.Size() == 1 && selection[0]->Type() == PCB_ZONE_T )
|
|
|
|
*aZone = static_cast<ZONE*>( selection[0] );
|
2017-02-06 05:59:55 +00:00
|
|
|
|
|
|
|
// expected a zone, but didn't get one
|
2020-06-16 09:47:07 +00:00
|
|
|
if( !*aZone )
|
2018-08-28 21:49:48 +00:00
|
|
|
{
|
|
|
|
if( clearSelection )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2018-08-28 21:49:48 +00:00
|
|
|
|
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
|
|
|
{
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor && !m_frame->GetModel() )
|
2019-07-19 21:13:52 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
ZONE_MODE zoneMode = aEvent.Parameter<ZONE_MODE>();
|
|
|
|
MODE drawMode = MODE::ZONE;
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::drawRuleArea ) )
|
2019-06-24 15:27:05 +00:00
|
|
|
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
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* sourceZone = nullptr;
|
2018-10-12 04:11:42 +00:00
|
|
|
|
2020-06-16 09:47:07 +00:00
|
|
|
if( !getSourceZoneForAction( zoneMode, &sourceZone ) )
|
2018-10-12 04:11:42 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-10-17 19:52:51 +00:00
|
|
|
// Turn zones on if they are off, so that the created object will be visible after completion
|
|
|
|
m_frame->SetObjectVisible( LAYER_ZONES );
|
|
|
|
|
2018-10-12 04:11:42 +00:00
|
|
|
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;
|
|
|
|
|
2020-06-27 21:08:13 +00:00
|
|
|
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();
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
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
|
2018-10-12 04:11:42 +00:00
|
|
|
POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool );
|
2021-09-13 12:23:10 +00:00
|
|
|
bool started = false;
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
2014-02-14 09:47:43 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2020-10-09 01:15:03 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
2020-10-08 02:47:01 +00:00
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2021-04-05 22:29:12 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
polyGeomMgr.Reset();
|
|
|
|
started = false;
|
|
|
|
grid.ClearSkipPoint();
|
|
|
|
m_controls->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( false );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
m_controls->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-04-05 22:29:12 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
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
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
LSET layers( m_frame->GetActiveLayer() );
|
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2021-03-04 01:09:24 +00:00
|
|
|
|
|
|
|
VECTOR2I cursorPos = evt->HasPosition() ? evt->Position() : m_controls->GetMousePosition();
|
2021-12-11 23:57:51 +00:00
|
|
|
cursorPos = GetClampedCoords( grid.BestSnapAnchor( cursorPos, layers ), COORDS_PADDING );
|
2021-03-04 01:09:24 +00:00
|
|
|
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
2014-02-17 10:33:03 +00:00
|
|
|
|
2022-05-29 20:28:10 +00:00
|
|
|
polyGeomMgr.SetLeaderMode( Is45Limited() ? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45
|
|
|
|
: POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
|
2019-10-20 16:27:44 +00:00
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
2014-02-13 11:46:39 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( started )
|
2021-05-21 13:53:32 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
2021-05-21 13:53:32 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2021-05-25 23:45:57 +00:00
|
|
|
// We've handled the cancel event. Don't cancel other tools
|
|
|
|
evt->SetPassEvent( false );
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( started )
|
2019-07-01 21:01:33 +00:00
|
|
|
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
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
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 ) )
|
|
|
|
{
|
2020-06-27 21:08:13 +00:00
|
|
|
if( zoneMode != ZONE_MODE::SIMILAR )
|
2018-10-12 04:11:42 +00:00
|
|
|
params.m_layer = frame()->GetActiveLayer();
|
2021-04-05 22:29:12 +00:00
|
|
|
|
|
|
|
if( !m_view->IsLayerVisible( params.m_layer ) )
|
|
|
|
{
|
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
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 )
|
2020-04-24 17:34:05 +00:00
|
|
|
|| evt->IsAction( &PCB_ACTIONS::closeOutline ) )
|
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 )
|
2020-04-24 17:34:05 +00:00
|
|
|
|| evt->IsAction( &PCB_ACTIONS::closeOutline )
|
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-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;
|
2021-04-05 22:29:12 +00:00
|
|
|
|
2018-10-12 04:11:42 +00:00
|
|
|
m_controls->SetAutoPan( true );
|
|
|
|
m_controls->CaptureCursor( true );
|
2021-04-05 22:29:12 +00:00
|
|
|
|
|
|
|
if( !m_view->IsLayerVisible( params.m_layer ) )
|
|
|
|
{
|
|
|
|
m_frame->GetAppearancePanel()->SetLayerVisible( params.m_layer, true );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( evt->IsAction( &PCB_ACTIONS::deleteLastPoint )
|
|
|
|
|| evt->IsAction( &ACTIONS::doDelete )
|
|
|
|
|| evt->IsAction( &ACTIONS::undo ) ) )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2023-06-19 16:09:03 +00:00
|
|
|
if( std::optional<VECTOR2I> last = polyGeomMgr.DeleteLastCorner() )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2023-06-19 16:09:03 +00:00
|
|
|
cursorPos = last.value();
|
|
|
|
getViewControls()->WarpMouseCursor( cursorPos, true );
|
|
|
|
m_controls->ForceCursorPosition( true, cursorPos );
|
|
|
|
polyGeomMgr.SetCursorPosition( cursorPos );
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else
|
2023-06-19 16:09:03 +00:00
|
|
|
{
|
|
|
|
cleanup();
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( evt->IsMotion()
|
|
|
|
|| evt->IsDrag( BUT_LEFT ) ) )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2019-10-20 16:27:44 +00:00
|
|
|
polyGeomMgr.SetCursorPosition( cursorPos );
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && ( ZONE_FILLER_TOOL::IsZoneFillAction( evt )
|
|
|
|
|| evt->IsAction( &ACTIONS::redo ) ) )
|
2020-09-17 21:29:40 +00:00
|
|
|
{
|
2022-11-14 23:39:08 +00:00
|
|
|
wxBell();
|
|
|
|
}
|
2023-07-15 16:37:17 +00:00
|
|
|
else if( started && evt->IsAction( &PCB_ACTIONS::properties ) )
|
2022-11-14 23:39:08 +00:00
|
|
|
{
|
|
|
|
frame()->OnEditItemRequest( zoneTool.GetZone() );
|
|
|
|
zoneTool.OnGeometryChange( polyGeomMgr );
|
|
|
|
frame()->SetMsgPanel( zoneTool.GetZone() );
|
2020-09-17 21:29:40 +00:00
|
|
|
}
|
2020-11-25 00:08:09 +00:00
|
|
|
/*else if( evt->IsAction( &ACTIONS::updateUnits ) )
|
2020-11-04 14:08:06 +00:00
|
|
|
{
|
|
|
|
// If we ever have an assistant here that reports dimensions, we'll want to
|
|
|
|
// update its units here....
|
|
|
|
// zoneAsst.SetUnits( frame()->GetUserUnits() );
|
|
|
|
// m_view->Update( &zoneAsst );
|
|
|
|
evt->SetPassEvent();
|
2020-11-25 00:08:09 +00:00
|
|
|
}*/
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-10-06 09:57:30 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-06 09:57:30 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
} // end while
|
2014-02-13 11:46:39 +00:00
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2018-11-13 13:58:54 +00:00
|
|
|
m_controls->ForceCursorPosition( false );
|
2021-05-21 13:53:32 +00:00
|
|
|
controls()->SetAutoPan( false );
|
|
|
|
m_controls->CaptureCursor( 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 )
|
|
|
|
{
|
2021-09-18 03:01:16 +00:00
|
|
|
if( m_isFootprintEditor )
|
|
|
|
return 0;
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
2021-02-01 22:45:56 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* m_frame;
|
|
|
|
PCB_GRID_HELPER m_gridHelper;
|
|
|
|
std::shared_ptr<DRC_ENGINE> m_drcEngine;
|
|
|
|
int m_drcEpsilon;
|
|
|
|
int m_worstClearance;
|
2021-02-14 22:31:11 +00:00
|
|
|
bool m_allowDRCViolations;
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
|
2021-02-01 22:45:56 +00:00
|
|
|
m_frame( aFrame ),
|
|
|
|
m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ),
|
|
|
|
m_drcEngine( aFrame->GetBoard()->GetDesignSettings().m_DRCEngine ),
|
|
|
|
m_drcEpsilon( aFrame->GetBoard()->GetDesignSettings().GetDRCEpsilon() ),
|
2021-08-01 20:51:08 +00:00
|
|
|
m_worstClearance( 0 )
|
2021-02-01 22:45:56 +00:00
|
|
|
{
|
2021-04-10 09:31:42 +00:00
|
|
|
ROUTER_TOOL* router = m_frame->GetToolManager()->GetTool<ROUTER_TOOL>();
|
2021-02-14 22:31:11 +00:00
|
|
|
|
2021-04-10 09:31:42 +00:00
|
|
|
m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations();
|
2021-02-14 22:31:11 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_drcEngine->InitEngine( aFrame->GetDesignRulesPath() );
|
|
|
|
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
|
|
|
|
if( m_drcEngine->QueryWorstConstraint( CLEARANCE_CONSTRAINT, constraint ) )
|
|
|
|
m_worstClearance = constraint.GetValue().Min();
|
|
|
|
|
|
|
|
if( m_drcEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, constraint ) )
|
|
|
|
m_worstClearance = std::max( m_worstClearance, constraint.GetValue().Min() );
|
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : aFrame->GetBoard()->Footprints() )
|
|
|
|
{
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
m_worstClearance = std::max( m_worstClearance, pad->GetLocalClearance() );
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 19:29:11 +00:00
|
|
|
catch( PARSE_ERROR& )
|
2021-02-01 22:45:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~VIA_PLACER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* findTrack( PCB_VIA* aVia )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2018-04-08 16:47:39 +00:00
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I position = aVia->GetPosition();
|
2022-01-30 10:52:52 +00:00
|
|
|
BOX2I bbox = aVia->GetBoundingBox();
|
2019-07-22 03:19:55 +00:00
|
|
|
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
|
2022-01-30 10:52:52 +00:00
|
|
|
KIGFX::PCB_VIEW* view = m_frame->GetCanvas()->GetView();
|
2021-06-11 21:07:02 +00:00
|
|
|
std::vector<PCB_TRACK*> possible_tracks;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
view->Query( bbox, items );
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& 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 );
|
|
|
|
|
2022-09-16 10:21:21 +00:00
|
|
|
if( !( item->GetLayerSet() & lset ).any() )
|
2018-04-08 16:47:39 +00:00
|
|
|
continue;
|
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
|
2019-01-23 15:18:44 +00:00
|
|
|
{
|
2023-06-24 18:54:50 +00:00
|
|
|
PCB_TRACK* track = static_cast<PCB_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 ) )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2019-01-25 15:12:04 +00:00
|
|
|
possible_tracks.push_back( track );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* return_track = nullptr;
|
2019-01-25 15:12:04 +00:00
|
|
|
int min_d = std::numeric_limits<int>::max();
|
2021-02-01 22:45:56 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : possible_tracks )
|
2019-01-25 15:12:04 +00:00
|
|
|
{
|
|
|
|
SEG test( track->GetStart(), track->GetEnd() );
|
2021-02-01 22:45:56 +00:00
|
|
|
int 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
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
bool hasDRCViolation( PCB_VIA* aVia, BOARD_ITEM* aOther )
|
2019-01-23 15:18:44 +00:00
|
|
|
{
|
2022-09-12 19:37:00 +00:00
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
int clearance;
|
|
|
|
BOARD_CONNECTED_ITEM* connectedItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aOther );
|
|
|
|
ZONE* zone = dynamic_cast<ZONE*>( aOther );
|
2022-02-24 21:01:03 +00:00
|
|
|
|
2022-09-12 19:37:00 +00:00
|
|
|
if( zone && zone->GetIsRuleArea() )
|
2022-02-24 21:01:03 +00:00
|
|
|
{
|
2022-09-12 19:37:00 +00:00
|
|
|
if( zone->GetDoNotAllowVias() )
|
|
|
|
return zone->Outline()->Collide( aVia->GetPosition(), aVia->GetWidth() / 2 );
|
2022-02-24 21:01:03 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-12 19:37:00 +00:00
|
|
|
if( connectedItem )
|
|
|
|
{
|
|
|
|
int connectedItemNet = connectedItem->GetNetCode();
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2022-09-12 19:37:00 +00:00
|
|
|
if( connectedItemNet == 0 || connectedItemNet == aVia->GetNetCode() )
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-14 22:31:11 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
for( PCB_LAYER_ID layer : aOther->GetLayerSet().Seq() )
|
2019-01-23 15:18:44 +00:00
|
|
|
{
|
2023-02-23 22:15:01 +00:00
|
|
|
// Bitmaps are "on" a copper layer but are not actually part of it
|
|
|
|
if( !IsCopperLayer( layer ) || aOther->Type() == PCB_BITMAP_T )
|
2021-02-14 22:31:11 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
constraint = m_drcEngine->EvalRules( CLEARANCE_CONSTRAINT, aVia, aOther, layer );
|
|
|
|
clearance = constraint.GetValue().Min();
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
if( clearance >= 0 )
|
2019-01-23 15:18:44 +00:00
|
|
|
{
|
2022-02-11 00:51:01 +00:00
|
|
|
std::shared_ptr<SHAPE> viaShape = aVia->GetEffectiveShape( layer );
|
|
|
|
std::shared_ptr<SHAPE> otherShape = aOther->GetEffectiveShape( layer );
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
if( viaShape->Collide( otherShape.get(), clearance - m_drcEpsilon ) )
|
|
|
|
return true;
|
2019-01-23 15:18:44 +00:00
|
|
|
}
|
2021-02-01 22:45:56 +00:00
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( aOther->HasHole() )
|
2021-02-14 22:31:11 +00:00
|
|
|
{
|
|
|
|
constraint = m_drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, aVia, aOther,
|
|
|
|
UNDEFINED_LAYER );
|
|
|
|
clearance = constraint.GetValue().Min();
|
|
|
|
|
|
|
|
if( clearance >= 0 )
|
|
|
|
{
|
2022-02-11 00:51:01 +00:00
|
|
|
std::shared_ptr<SHAPE> viaShape = aVia->GetEffectiveShape( UNDEFINED_LAYER );
|
2021-02-14 22:31:11 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( viaShape->Collide( aOther->GetEffectiveHoleShape().get(),
|
|
|
|
clearance - m_drcEpsilon ) )
|
|
|
|
{
|
2021-02-14 22:31:11 +00:00
|
|
|
return true;
|
2022-07-22 22:05:25 +00:00
|
|
|
}
|
2021-02-14 22:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-22 03:19:55 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
bool checkDRCViolation( PCB_VIA* aVia )
|
2021-02-01 22:45:56 +00:00
|
|
|
{
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
|
2021-02-14 22:31:11 +00:00
|
|
|
std::set<BOARD_ITEM*> checkedItems;
|
2021-02-01 22:45:56 +00:00
|
|
|
BOX2I bbox = aVia->GetBoundingBox();
|
2019-07-22 03:19:55 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
bbox.Inflate( m_worstClearance );
|
|
|
|
m_frame->GetCanvas()->GetView()->Query( bbox, items );
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
for( std::pair<KIGFX::VIEW_ITEM*, int> it : items )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( it.first );
|
2019-07-22 03:19:55 +00:00
|
|
|
|
2021-02-14 22:31:11 +00:00
|
|
|
if( !item )
|
|
|
|
continue;
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T && !static_cast<ZONE*>( item )->GetIsRuleArea() )
|
2022-02-24 21:01:03 +00:00
|
|
|
{
|
2021-02-17 10:56:06 +00:00
|
|
|
continue; // stitching vias bind to zones, so ignore them
|
2022-02-24 21:01:03 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_GROUP_T )
|
|
|
|
{
|
2021-02-17 10:56:06 +00:00
|
|
|
continue; // check against children, but not against footprint itself
|
2022-02-24 21:01:03 +00:00
|
|
|
}
|
2023-06-06 15:09:34 +00:00
|
|
|
else if( ( item->Type() == PCB_FIELD_T || item->Type() == PCB_TEXT_T )
|
|
|
|
&& !static_cast<PCB_TEXT*>( item )->IsVisible() )
|
2022-02-24 21:01:03 +00:00
|
|
|
{
|
2021-02-17 10:56:06 +00:00
|
|
|
continue; // ignore hidden items
|
2022-02-24 21:01:03 +00:00
|
|
|
}
|
|
|
|
else if( checkedItems.count( item ) )
|
|
|
|
{
|
|
|
|
continue; // already checked
|
|
|
|
}
|
2019-07-22 03:19:55 +00:00
|
|
|
|
2021-02-01 22:45:56 +00:00
|
|
|
if( hasDRCViolation( aVia, item ) )
|
|
|
|
return true;
|
|
|
|
|
2021-02-14 22:31:11 +00:00
|
|
|
checkedItems.insert( item );
|
2019-01-23 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 20:45:33 +00:00
|
|
|
DRC_CONSTRAINT constraint = m_drcEngine->EvalRules( DISALLOW_CONSTRAINT, aVia, nullptr,
|
|
|
|
UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
if( constraint.m_DisallowFlags && constraint.GetSeverity() != RPT_SEVERITY_IGNORE )
|
|
|
|
return true;
|
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PAD* findPad( PCB_VIA* aVia )
|
2021-04-02 15:19:44 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I position = aVia->GetPosition();
|
2022-01-30 10:52:52 +00:00
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2021-04-02 15:19:44 +00:00
|
|
|
|
|
|
|
for( FOOTPRINT* fp : m_board->Footprints() )
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
for( PAD* pad : fp->Pads() )
|
2021-04-02 15:19:44 +00:00
|
|
|
{
|
|
|
|
if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2021-04-02 15:19:44 +00:00
|
|
|
if( pad->GetNetCode() > 0 )
|
|
|
|
return pad;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2021-04-02 15:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
int findStitchedZoneNet( PCB_VIA* aVia )
|
2018-04-08 16:47:39 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I position = aVia->GetPosition();
|
2022-02-24 21:09:47 +00:00
|
|
|
const LSET lset = aVia->GetLayerSet();
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2022-02-24 21:09:47 +00:00
|
|
|
// first take the net of the active layer
|
|
|
|
if( lset.test( m_frame->GetActiveLayer() ) )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2022-02-24 21:09:47 +00:00
|
|
|
for( ZONE* z : m_board->Zones() )
|
2020-10-13 17:46:48 +00:00
|
|
|
{
|
2022-02-24 21:09:47 +00:00
|
|
|
if( z->IsOnLayer( m_frame->GetActiveLayer() ) )
|
2020-11-11 23:05:59 +00:00
|
|
|
{
|
2022-02-24 21:09:47 +00:00
|
|
|
if( z->HitTestFilledArea( m_frame->GetActiveLayer(), position ) )
|
|
|
|
return z->GetNetCode();
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
// none? take the topmost visible layer
|
2022-02-24 21:09:47 +00:00
|
|
|
for( PCB_LAYER_ID layer : LSET( m_board->GetVisibleLayers() & lset ).Seq() )
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2022-02-24 21:09:47 +00:00
|
|
|
for( ZONE* z : m_board->Zones() )
|
|
|
|
{
|
2022-09-16 10:21:21 +00:00
|
|
|
if( z->IsOnLayer( layer ) )
|
2022-02-24 21:09:47 +00:00
|
|
|
{
|
|
|
|
if( z->HitTestFilledArea( layer, position ) )
|
|
|
|
return z->GetNetCode();
|
|
|
|
}
|
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
}
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
void SnapItem( BOARD_ITEM *aItem ) override
|
|
|
|
{
|
2018-10-04 00:15:54 +00:00
|
|
|
m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
|
2018-05-07 20:49:36 +00:00
|
|
|
|
2022-04-11 15:09:27 +00:00
|
|
|
MAGNETIC_SETTINGS* settings = m_frame->GetMagneticItemsSettings();
|
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
|
|
|
|
VECTOR2I position = via->GetPosition();
|
|
|
|
|
|
|
|
if( settings->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS && m_gridHelper.GetSnap() )
|
2018-04-08 16:47:39 +00:00
|
|
|
{
|
2022-04-11 15:09:27 +00:00
|
|
|
PCB_TRACK* track = findTrack( via );
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2022-04-11 15:09:27 +00:00
|
|
|
if( track )
|
|
|
|
{
|
|
|
|
SEG trackSeg( track->GetStart(), track->GetEnd() );
|
|
|
|
VECTOR2I snap = m_gridHelper.AlignToSegment( position, trackSeg );
|
|
|
|
|
|
|
|
aItem->SetPosition( snap );
|
|
|
|
}
|
2018-04-08 16:47:39 +00:00
|
|
|
}
|
2022-04-11 15:09:27 +00:00
|
|
|
else if( settings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS && m_gridHelper.GetSnap() )
|
2021-12-06 14:35:10 +00:00
|
|
|
{
|
2022-04-11 15:09:27 +00:00
|
|
|
PAD* pad = findPad( via );
|
|
|
|
|
|
|
|
if( pad )
|
|
|
|
{
|
|
|
|
aItem->SetPosition( pad->GetPosition() );
|
|
|
|
}
|
2021-12-06 14:35:10 +00:00
|
|
|
}
|
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
|
|
|
{
|
2021-08-01 20:51:08 +00:00
|
|
|
WX_INFOBAR* infobar = m_frame->GetInfoBar();
|
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I viaPos = via->GetPosition();
|
2021-08-01 20:51:08 +00:00
|
|
|
PCB_TRACK* track = findTrack( via );
|
|
|
|
PAD* pad = findPad( via );
|
2018-04-08 16:47:39 +00:00
|
|
|
|
2021-02-17 19:36:09 +00:00
|
|
|
if( track )
|
2022-09-15 17:35:26 +00:00
|
|
|
{
|
2021-02-17 19:36:09 +00:00
|
|
|
via->SetNetCode( track->GetNetCode() );
|
2022-09-15 17:35:26 +00:00
|
|
|
via->SetIsFree( false );
|
|
|
|
}
|
2021-04-02 15:19:44 +00:00
|
|
|
else if( pad )
|
2022-09-15 17:35:26 +00:00
|
|
|
{
|
2021-04-02 15:19:44 +00:00
|
|
|
via->SetNetCode( pad->GetNetCode() );
|
2022-09-15 17:35:26 +00:00
|
|
|
via->SetIsFree( false );
|
|
|
|
}
|
2021-09-01 22:52:35 +00:00
|
|
|
else
|
2022-09-15 17:35:26 +00:00
|
|
|
{
|
2021-09-01 22:52:35 +00:00
|
|
|
via->SetNetCode( findStitchedZoneNet( via ) );
|
2022-09-15 17:35:26 +00:00
|
|
|
via->SetIsFree( via->GetNetCode() > 0 );
|
|
|
|
}
|
2021-02-17 19:36:09 +00:00
|
|
|
|
2022-09-15 17:35:26 +00:00
|
|
|
if( checkDRCViolation( via ) )
|
2021-02-01 22:45:56 +00:00
|
|
|
{
|
2021-08-01 20:51:08 +00:00
|
|
|
m_frame->ShowInfoBarError( _( "Via location violates DRC." ), true,
|
|
|
|
WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
|
2022-09-15 17:35:26 +00:00
|
|
|
|
|
|
|
if( !m_allowDRCViolations )
|
|
|
|
return false;
|
2021-02-01 22:45:56 +00:00
|
|
|
}
|
2021-08-01 20:51:08 +00:00
|
|
|
else
|
2021-02-01 22:45:56 +00:00
|
|
|
{
|
2021-08-01 20:51:08 +00:00
|
|
|
if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION )
|
|
|
|
infobar->Dismiss();
|
2021-02-01 22:45:56 +00:00
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
|
2022-04-11 15:09:27 +00:00
|
|
|
aCommit.Add( via );
|
|
|
|
|
2022-12-14 21:50:48 +00:00
|
|
|
// If the user explicitly disables snap (using shift), then don't break the tracks into
|
|
|
|
// a chevron. This will prevent PNS from being able to connect the via and track but
|
|
|
|
// it is explicitly requested by the user
|
|
|
|
if( track && m_gridHelper.GetSnap() )
|
2018-04-08 16:47:39 +00:00
|
|
|
{
|
2022-04-11 15:09:27 +00:00
|
|
|
VECTOR2I trackStart = track->GetStart();
|
|
|
|
VECTOR2I trackEnd = track->GetEnd();
|
|
|
|
SEG trackSeg( trackStart, trackEnd );
|
2022-08-30 20:58:43 +00:00
|
|
|
|
|
|
|
OPT_VECTOR2I joint1;
|
|
|
|
OPT_VECTOR2I joint2;
|
2022-04-11 15:09:27 +00:00
|
|
|
|
|
|
|
auto insertChevron =
|
|
|
|
[&]()
|
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
if( ( trackStart - *joint1 ).SquaredEuclideanNorm()
|
|
|
|
> ( trackStart - *joint2 ).SquaredEuclideanNorm() )
|
2022-04-11 15:09:27 +00:00
|
|
|
{
|
|
|
|
std::swap( joint1, joint2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
aCommit.Modify( track );
|
|
|
|
track->SetStart( trackStart );
|
2022-08-30 20:58:43 +00:00
|
|
|
track->SetEnd( *joint1 );
|
2022-04-11 15:09:27 +00:00
|
|
|
|
2023-03-16 00:15:55 +00:00
|
|
|
if( *joint1 != viaPos )
|
|
|
|
{
|
|
|
|
PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
|
|
|
|
wxCHECK( newTrack, /* void */ );
|
|
|
|
const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
|
2022-04-11 15:09:27 +00:00
|
|
|
|
2023-03-16 00:15:55 +00:00
|
|
|
newTrack->SetStart( *joint1 );
|
|
|
|
newTrack->SetEnd( viaPos );
|
|
|
|
aCommit.Add( newTrack );
|
|
|
|
}
|
2022-04-11 15:09:27 +00:00
|
|
|
|
2023-03-16 00:15:55 +00:00
|
|
|
if( *joint2 != viaPos )
|
|
|
|
{
|
|
|
|
PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
|
|
|
|
wxCHECK( newTrack, /* void */ );
|
|
|
|
const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
|
2022-04-11 15:09:27 +00:00
|
|
|
|
2023-03-16 00:15:55 +00:00
|
|
|
newTrack->SetStart( viaPos );
|
|
|
|
newTrack->SetEnd( *joint2 );
|
|
|
|
aCommit.Add( newTrack );
|
|
|
|
}
|
2022-04-11 15:09:27 +00:00
|
|
|
|
2023-03-16 00:15:55 +00:00
|
|
|
PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
|
2022-10-17 13:19:39 +00:00
|
|
|
wxCHECK( newTrack, /* void */ );
|
2022-04-11 15:09:27 +00:00
|
|
|
const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
|
|
|
|
|
2022-08-30 20:58:43 +00:00
|
|
|
newTrack->SetStart( *joint2 );
|
2022-04-11 15:09:27 +00:00
|
|
|
newTrack->SetEnd( trackEnd );
|
|
|
|
aCommit.Add( newTrack );
|
|
|
|
};
|
|
|
|
|
|
|
|
if( viaPos == trackStart || viaPos == trackEnd )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( trackStart.x == trackEnd.x )
|
2019-07-06 21:53:50 +00:00
|
|
|
{
|
2022-04-11 15:09:27 +00:00
|
|
|
VECTOR2I splitPt = trackSeg.NearestPoint( viaPos );
|
|
|
|
|
|
|
|
if( splitPt.x != viaPos.x
|
|
|
|
&& abs( splitPt.x - viaPos.x ) < abs( splitPt.y - trackStart.y )
|
|
|
|
&& abs( splitPt.x - viaPos.x ) < abs( splitPt.y - trackEnd.y ) )
|
|
|
|
{
|
|
|
|
int offset = abs( splitPt.x - viaPos.x );
|
2020-08-10 13:39:43 +00:00
|
|
|
|
2022-04-11 15:09:27 +00:00
|
|
|
joint1 = VECTOR2I( splitPt.x, splitPt.y - offset );
|
|
|
|
joint2 = VECTOR2I( splitPt.x, splitPt.y + offset );
|
2020-08-10 13:39:43 +00:00
|
|
|
|
2022-04-11 15:09:27 +00:00
|
|
|
insertChevron();
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-06 21:53:50 +00:00
|
|
|
}
|
2022-04-11 15:09:27 +00:00
|
|
|
else if( trackStart.y == trackEnd.y )
|
|
|
|
{
|
|
|
|
VECTOR2I splitPt = trackSeg.NearestPoint( viaPos );
|
|
|
|
|
|
|
|
if( splitPt.y != viaPos.y
|
|
|
|
&& abs( trackStart.y - viaPos.y ) < abs( trackStart.x - viaPos.x )
|
|
|
|
&& abs( trackEnd.y - viaPos.y ) < abs( trackEnd.x - viaPos.x ) )
|
|
|
|
{
|
|
|
|
int offset = abs( splitPt.y - viaPos.y );
|
|
|
|
|
|
|
|
joint1 = VECTOR2I( splitPt.x - offset, splitPt.y );
|
|
|
|
joint2 = VECTOR2I( splitPt.x + offset, splitPt.y );
|
|
|
|
|
|
|
|
insertChevron();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( abs( trackStart.y - trackEnd.y ) == abs( trackStart.x - trackEnd.x ) )
|
|
|
|
{
|
|
|
|
SEG horiz( VECTOR2I( -INT_MAX, viaPos.y ), VECTOR2I( INT_MAX, viaPos.y ) );
|
|
|
|
SEG vert( VECTOR2I( viaPos.x, -INT_MAX ), VECTOR2I( viaPos.x, INT_MAX ) );
|
|
|
|
|
|
|
|
if( track->GetBoundingBox().Contains( viaPos ) )
|
|
|
|
{
|
2022-08-30 20:58:43 +00:00
|
|
|
joint1 = trackSeg.Intersect( horiz, true, true );
|
|
|
|
joint2 = trackSeg.Intersect( vert, true, true );
|
|
|
|
|
|
|
|
if( !joint1 || !joint2 )
|
|
|
|
return false;
|
2022-04-11 15:09:27 +00:00
|
|
|
|
|
|
|
insertChevron();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aCommit.Modify( track );
|
|
|
|
track->SetStart( trackStart );
|
|
|
|
track->SetEnd( viaPos );
|
|
|
|
|
|
|
|
PCB_TRACK* newTrack = dynamic_cast<PCB_TRACK*>( track->Clone() );
|
|
|
|
const_cast<KIID&>( newTrack->m_Uuid ) = KIID();
|
|
|
|
|
|
|
|
newTrack->SetStart( viaPos );
|
|
|
|
newTrack->SetEnd( trackEnd );
|
|
|
|
aCommit.Add( newTrack );
|
2020-12-20 21:29:43 +00:00
|
|
|
}
|
2017-04-22 15:46:31 +00:00
|
|
|
|
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
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
PCB_VIA* via = new PCB_VIA( m_board );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
via->SetNetCode( 0 );
|
2021-06-11 21:07:02 +00:00
|
|
|
via->SetViaType( bds.m_CurrentViaType );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
// for microvias, the size and hole will be changed later.
|
2021-06-11 21:07:02 +00:00
|
|
|
via->SetWidth( bds.GetCurrentViaSize() );
|
|
|
|
via->SetDrill( bds.GetCurrentViaDrill() );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
// 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() )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
case VIATYPE::BLIND_BURIED:
|
2017-04-22 15:46:31 +00:00
|
|
|
via->SetLayerPair( first_layer, last_layer );
|
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case VIATYPE::MICROVIA: // from external to the near neighbor inner layer
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
2020-12-08 12:30:07 +00:00
|
|
|
// Update diameter and hole size, which where set previously for normal vias
|
2022-08-14 11:03:18 +00:00
|
|
|
NETCLASS* netClass = via->GetEffectiveNetClass();
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2020-12-08 12:30:07 +00:00
|
|
|
via->SetWidth( netClass->GetuViaDiameter() );
|
|
|
|
via->SetDrill( netClass->GetuViaDrill() );
|
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
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
doInteractiveItemPlacement( aEvent, &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
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
const unsigned int DRAWING_TOOL::WIDTH_STEP = pcbIUScale.mmToIU( 0.1 );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DRAWING_TOOL::setTransitions()
|
|
|
|
{
|
2021-03-13 20:19:46 +00:00
|
|
|
|
|
|
|
Go( &DRAWING_TOOL::PlaceStackup, PCB_ACTIONS::placeStackup.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::PlaceCharacteristics, PCB_ACTIONS::placeCharacteristics.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawPolygon.MakeEvent() );
|
2020-06-15 19:50:20 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawRectangle, PCB_ACTIONS::drawRectangle.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawArc, PCB_ACTIONS::drawArc.MakeEvent() );
|
2020-09-12 20:09:40 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawAlignedDimension.MakeEvent() );
|
2020-09-22 02:32:40 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawOrthogonalDimension.MakeEvent() );
|
2020-09-17 00:54:58 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawCenterDimension.MakeEvent() );
|
2021-07-13 18:46:33 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawRadialDimension.MakeEvent() );
|
2020-09-12 20:09:40 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawLeader.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZone.MakeEvent() );
|
2020-09-21 23:32:07 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawRuleArea.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZoneCutout.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawSimilarZone.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::DrawVia, PCB_ACTIONS::drawVia.MakeEvent() );
|
2022-02-08 19:29:54 +00:00
|
|
|
Go( &DRAWING_TOOL::PlaceImage, PCB_ACTIONS::placeImage.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::PlaceText, PCB_ACTIONS::placeText.MakeEvent() );
|
2022-01-30 10:52:52 +00:00
|
|
|
Go( &DRAWING_TOOL::DrawRectangle, PCB_ACTIONS::drawTextBox.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() );
|
|
|
|
Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() );
|
2022-05-29 13:16:13 +00:00
|
|
|
Go( &DRAWING_TOOL::ToggleHV45Mode, PCB_ACTIONS::toggleHV45Mode.MakeEvent() );
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|