2020-05-22 18:27:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-02-12 16:32:55 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-22 18:27:05 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <footprint_editor_settings.h>
|
2021-08-05 12:03:59 +00:00
|
|
|
#include <3d_viewer/eda_3d_viewer_frame.h>
|
2020-06-03 14:58:54 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2020-05-22 18:27:05 +00:00
|
|
|
#include <pcb_base_frame.h>
|
|
|
|
#include <preview_items/ruler_item.h>
|
|
|
|
#include <tool/actions.h>
|
2021-01-16 23:17:32 +00:00
|
|
|
#include <tools/pcb_grid_helper.h>
|
2020-05-22 18:27:05 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/pcb_viewer_tools.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_VIEWER_TOOLS::Init()
|
|
|
|
{
|
|
|
|
// Populate the context menu displayed during the tool (primarily the measure tool)
|
|
|
|
auto activeToolCondition =
|
2022-02-12 16:32:55 +00:00
|
|
|
[ this ] ( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return !frame()->ToolStackIsEmpty();
|
|
|
|
};
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2022-02-12 16:32:55 +00:00
|
|
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
// "Cancel" goes at the top of the context menu when a tool is active
|
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
|
|
|
|
ctxMenu.AddSeparator( 1 );
|
|
|
|
|
|
|
|
frame()->AddStandardSubMenus( m_menu );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_VIEWER_TOOLS::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_VIEWER_TOOLS::Show3DViewer( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_VIEWER_FRAME* draw3DFrame = frame()->CreateAndShow3D_Frame();
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
if( frame()->IsType( FRAME_FOOTPRINT_VIEWER )
|
|
|
|
|| frame()->IsType( FRAME_FOOTPRINT_VIEWER_MODAL )
|
|
|
|
|| frame()->IsType( FRAME_FOOTPRINT_WIZARD ) )
|
|
|
|
{
|
|
|
|
// A stronger version of Raise() which promotes the window to its parent's level.
|
2020-06-03 14:58:54 +00:00
|
|
|
KIPLATFORM::UI::ReparentQuasiModal( draw3DFrame );
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
2021-07-19 08:10:25 +00:00
|
|
|
|
|
|
|
// And load or update the current board
|
|
|
|
frame()->Update3DView( true, true );
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> void Flip( T& aValue )
|
|
|
|
{
|
|
|
|
aValue = !aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-23 17:14:49 +00:00
|
|
|
int PCB_VIEWER_TOOLS::ShowPadNumbers( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-07-24 15:49:46 +00:00
|
|
|
PCB_VIEWERS_SETTINGS_BASE* cfg = frame()->GetViewerSettingsBase();
|
|
|
|
Flip( cfg->m_ViewersDisplay.m_DisplayPadNumbers );
|
2020-05-23 17:14:49 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : board()->Footprints() )
|
2020-05-23 17:14:49 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : fp->Pads() )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( pad, KIGFX::REPAINT );
|
2020-05-23 17:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
int PCB_VIEWER_TOOLS::PadDisplayMode( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2022-07-24 15:49:46 +00:00
|
|
|
PCB_VIEWERS_SETTINGS_BASE* cfg = frame()->GetViewerSettingsBase();
|
|
|
|
Flip( cfg->m_ViewersDisplay.m_DisplayPadFill );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : board()->Footprints() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : fp->Pads() )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( pad, KIGFX::REPAINT );
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-26 22:21:38 +00:00
|
|
|
int PCB_VIEWER_TOOLS::GraphicOutlines( const TOOL_EVENT& aEvent )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2022-07-24 15:49:46 +00:00
|
|
|
PCB_VIEWERS_SETTINGS_BASE* cfg = frame()->GetViewerSettingsBase();
|
|
|
|
Flip( cfg->m_ViewersDisplay.m_DisplayGraphicsFill );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : board()->Footprints() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : fp->GraphicalItems() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2021-12-04 23:52:00 +00:00
|
|
|
KICAD_T t = item->Type();
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( t == PCB_SHAPE_T || BaseType( t ) == PCB_DIMENSION_T )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( item, KIGFX::REPAINT );
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 22:21:38 +00:00
|
|
|
for( BOARD_ITEM* item : board()->Drawings() )
|
|
|
|
{
|
|
|
|
KICAD_T t = item->Type();
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( t == PCB_SHAPE_T || BaseType( t ) == PCB_DIMENSION_T || t == PCB_TARGET_T )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( item, KIGFX::REPAINT );
|
2020-05-26 22:21:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-26 22:21:38 +00:00
|
|
|
int PCB_VIEWER_TOOLS::TextOutlines( const TOOL_EVENT& aEvent )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2022-07-24 15:49:46 +00:00
|
|
|
PCB_VIEWERS_SETTINGS_BASE* cfg = frame()->GetViewerSettingsBase();
|
|
|
|
Flip( cfg->m_ViewersDisplay.m_DisplayTextFill );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : board()->Footprints() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2023-06-06 15:09:34 +00:00
|
|
|
for( PCB_FIELD* field : fp->Fields() )
|
|
|
|
{
|
|
|
|
view()->Update( field, KIGFX::REPAINT );
|
|
|
|
}
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2020-10-14 23:37:26 +00:00
|
|
|
for( BOARD_ITEM* item : fp->GraphicalItems() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_TEXT_T )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( item, KIGFX::REPAINT );
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 22:21:38 +00:00
|
|
|
for( BOARD_ITEM* item : board()->Drawings() )
|
|
|
|
{
|
|
|
|
KICAD_T t = item->Type();
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
if( t == PCB_TEXT_T || t == PCB_TEXTBOX_T || BaseType( t ) == PCB_DIMENSION_T )
|
2021-04-08 21:35:51 +00:00
|
|
|
view()->Update( item, KIGFX::REPAINT );
|
2020-05-26 22:21:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
using KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER;
|
|
|
|
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( IsFootprintFrame() && !frame()->GetModel() )
|
|
|
|
return 0;
|
|
|
|
|
2020-12-10 22:08:09 +00:00
|
|
|
if( frame()->IsCurrentTool( ACTIONS::measureTool ) )
|
|
|
|
return 0;
|
|
|
|
|
2020-05-22 18:27:05 +00:00
|
|
|
auto& view = *getView();
|
|
|
|
auto& controls = *getViewControls();
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PushTool( aEvent );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
|
|
|
|
bool originSet = false;
|
2020-05-22 18:27:05 +00:00
|
|
|
EDA_UNITS units = frame()->GetUserUnits();
|
2022-09-16 04:38:10 +00:00
|
|
|
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, pcbIUScale, units,
|
2021-12-26 00:36:12 +00:00
|
|
|
displayOptions().m_DisplayInvertXAxis,
|
|
|
|
displayOptions().m_DisplayInvertYAxis );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
view.Add( &ruler );
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
|
2021-04-09 02:09:06 +00:00
|
|
|
auto setCursor =
|
2020-12-10 22:08:09 +00:00
|
|
|
[&]()
|
2021-04-09 02:09:06 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
controls.ForceCursorPosition( false );
|
2021-09-13 12:23:10 +00:00
|
|
|
originSet = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls.ShowCursor( true );
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
controls.ForceCursorPosition( false );
|
|
|
|
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2020-05-22 18:27:05 +00:00
|
|
|
|
2020-10-07 23:45:47 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2020-05-22 18:27:05 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-09 19:17:01 +00:00
|
|
|
grid.SetUseGrid( view.GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2020-05-22 18:27:05 +00:00
|
|
|
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
|
2022-04-10 22:14:30 +00:00
|
|
|
controls.ForceCursorPosition( true, cursorPos );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
|
|
|
if( originSet )
|
2021-05-21 13:53:32 +00:00
|
|
|
{
|
2021-09-13 12:23:10 +00:00
|
|
|
cleanup();
|
2021-05-21 13:53:32 +00:00
|
|
|
}
|
2020-05-22 18:27:05 +00:00
|
|
|
else
|
|
|
|
{
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PopTool( aEvent );
|
2020-05-22 18:27:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( originSet )
|
2021-09-13 12:23:10 +00:00
|
|
|
cleanup();
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
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
|
|
|
frame()->PopTool( aEvent );
|
2020-05-22 18:27:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// click or drag starts
|
|
|
|
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
twoPtMgr.SetOrigin( cursorPos );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
controls.CaptureCursor( true );
|
|
|
|
controls.SetAutoPan( true );
|
|
|
|
|
|
|
|
originSet = true;
|
|
|
|
}
|
|
|
|
// second click or mouse up after drag ends
|
|
|
|
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
originSet = false;
|
|
|
|
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
}
|
|
|
|
// move or drag when origin set updates rules
|
|
|
|
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
bool force45Deg;
|
2021-10-01 11:11:03 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
if( frame()->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
force45Deg = mgr.GetAppSettings<PCBNEW_SETTINGS>()->m_Use45DegreeLimit;
|
|
|
|
else
|
|
|
|
force45Deg = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>()->m_Use45Limit;
|
2021-10-01 11:11:03 +00:00
|
|
|
|
|
|
|
twoPtMgr.SetAngleSnap( force45Deg );
|
2020-05-22 18:27:05 +00:00
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, true );
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
}
|
2020-11-04 14:08:06 +00:00
|
|
|
else if( evt->IsAction( &ACTIONS::updateUnits ) )
|
2020-05-22 18:27:05 +00:00
|
|
|
{
|
|
|
|
if( frame()->GetUserUnits() != units )
|
|
|
|
{
|
|
|
|
units = frame()->GetUserUnits();
|
2020-10-04 16:14:37 +00:00
|
|
|
ruler.SwitchUnits( units );
|
2020-05-22 18:27:05 +00:00
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
canvas()->Refresh();
|
|
|
|
}
|
2021-11-23 20:51:37 +00:00
|
|
|
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACTIONS::updatePreferences ) )
|
|
|
|
{
|
2021-12-26 00:36:12 +00:00
|
|
|
ruler.UpdateDir( displayOptions().m_DisplayInvertXAxis,
|
|
|
|
displayOptions().m_DisplayInvertYAxis );
|
2021-11-23 20:51:37 +00:00
|
|
|
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
canvas()->Refresh();
|
2020-11-04 14:08:06 +00:00
|
|
|
evt->SetPassEvent();
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu();
|
|
|
|
}
|
|
|
|
else
|
2020-11-04 14:08:06 +00:00
|
|
|
{
|
2020-05-22 18:27:05 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-04 14:08:06 +00:00
|
|
|
}
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
view.Remove( &ruler );
|
2020-11-19 20:08:58 +00:00
|
|
|
|
|
|
|
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2021-05-21 13:53:32 +00:00
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
2022-04-10 22:14:30 +00:00
|
|
|
controls.ForceCursorPosition( false );
|
2020-05-22 18:27:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_VIEWER_TOOLS::setTransitions()
|
|
|
|
{
|
2020-05-26 22:21:38 +00:00
|
|
|
Go( &PCB_VIEWER_TOOLS::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() );
|
2020-05-22 18:27:05 +00:00
|
|
|
|
|
|
|
// Display modes
|
2020-05-26 22:21:38 +00:00
|
|
|
Go( &PCB_VIEWER_TOOLS::ShowPadNumbers, PCB_ACTIONS::showPadNumbers.MakeEvent() );
|
|
|
|
Go( &PCB_VIEWER_TOOLS::PadDisplayMode, PCB_ACTIONS::padDisplayMode.MakeEvent() );
|
|
|
|
Go( &PCB_VIEWER_TOOLS::GraphicOutlines, PCB_ACTIONS::graphicsOutlines.MakeEvent() );
|
|
|
|
Go( &PCB_VIEWER_TOOLS::TextOutlines, PCB_ACTIONS::textOutlines.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &PCB_VIEWER_TOOLS::MeasureTool, ACTIONS::measureTool.MakeEvent() );
|
2020-05-22 18:27:05 +00:00
|
|
|
}
|