Push shared parts of GRID_HELPERs into common.

This commit is contained in:
Jeff Young 2021-01-16 23:17:32 +00:00
parent 950db6ff9c
commit 68efdb2fff
21 changed files with 501 additions and 632 deletions

View File

@ -431,6 +431,7 @@ set( COMMON_SRCS
tool/edit_constraints.cpp tool/edit_constraints.cpp
tool/edit_points.cpp tool/edit_points.cpp
tool/editor_conditions.cpp tool/editor_conditions.cpp
tool/grid_helper.cpp
tool/grid_menu.cpp tool/grid_menu.cpp
tool/picker_tool.cpp tool/picker_tool.cpp
tool/selection_conditions.cpp tool/selection_conditions.cpp
@ -560,7 +561,7 @@ set( PCB_COMMON_SRCS
${CMAKE_SOURCE_DIR}/pcbnew/sel_layer.cpp ${CMAKE_SOURCE_DIR}/pcbnew/sel_layer.cpp
${CMAKE_SOURCE_DIR}/pcbnew/zone_settings.cpp ${CMAKE_SOURCE_DIR}/pcbnew/zone_settings.cpp
${CMAKE_SOURCE_DIR}/pcbnew/tools/grid_helper.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_grid_helper.cpp
${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_actions.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_actions.cpp
${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_editor_conditions.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_editor_conditions.cpp
${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_viewer_tools.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_viewer_tools.cpp

113
common/tool/grid_helper.cpp Normal file
View File

@ -0,0 +1,113 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <functional>
using namespace std::placeholders;
#include <math/util.h> // for KiROUND
#include <math/vector2d.h>
#include <tool/tool_manager.h>
#include <view/view.h>
#include <tool/grid_helper.h>
GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr ) :
m_toolMgr( aToolMgr )
{
m_enableSnap = true;
m_enableSnapLine = true;
m_enableGrid = true;
m_snapItem = nullptr;
}
GRID_HELPER::~GRID_HELPER()
{
}
VECTOR2I GRID_HELPER::GetGrid() const
{
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetGridSize();
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
}
VECTOR2I GRID_HELPER::GetOrigin() const
{
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
return VECTOR2I( origin );
}
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
{
if( aEnable )
{
m_auxAxis = aOrigin;
m_viewAxis.SetPosition( wxPoint( aOrigin ) );
m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
}
else
{
m_auxAxis = OPT<VECTOR2I>();
m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
}
}
VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const
{
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D grid( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
return nearest;
}
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
{
if( !m_toolMgr->GetView()->GetGAL()->GetGridSnapping() )
return aPoint;
VECTOR2I nearest = AlignGrid( aPoint );
if( !m_auxAxis )
return nearest;
if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
nearest.x = m_auxAxis->x;
if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
nearest.y = m_auxAxis->y;
return nearest;
}

View File

@ -23,38 +23,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* EE_GRID_HELPER
*
* A helper class for doing grid and object snapping.
*
* It shares its roots with PCBNew's GRID_HELPER, but uses the layers architecture to split
* connectable items from graphic items.
*/
#include <functional> #include <functional>
using namespace std::placeholders;
#include <geometry/shape_line_chain.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
#include <math/vector2d.h>
#include <sch_item.h> #include <sch_item.h>
#include <sch_painter.h> #include <sch_painter.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <view/view.h> #include <view/view.h>
#include <view/view_controls.h>
#include "ee_grid_helper.h" #include "ee_grid_helper.h"
EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) : EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) :
m_toolMgr( aToolMgr ) GRID_HELPER( aToolMgr )
{ {
m_enableSnap = true;
m_enableSnapLine = true;
m_enableGrid = true;
m_snapItem = nullptr;
KIGFX::VIEW* view = m_toolMgr->GetView(); KIGFX::VIEW* view = m_toolMgr->GetView();
m_viewAxis.SetSize( 20000 ); m_viewAxis.SetSize( 20000 );
@ -78,112 +57,6 @@ EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) :
} }
EE_GRID_HELPER::~EE_GRID_HELPER()
{
}
VECTOR2I EE_GRID_HELPER::GetGrid() const
{
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetGridSize();
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
}
VECTOR2I EE_GRID_HELPER::GetOrigin() const
{
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
return VECTOR2I( origin );
}
void EE_GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
{
if( aEnable )
{
m_auxAxis = aOrigin;
m_viewAxis.SetPosition( wxPoint( aOrigin ) );
m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
}
else
{
m_auxAxis = OPT<VECTOR2I>();
m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
}
}
VECTOR2I EE_GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const
{
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D grid( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
return nearest;
}
VECTOR2I EE_GRID_HELPER::Align( const VECTOR2I& aPoint ) const
{
if( !m_toolMgr->GetView()->GetGAL()->GetGridSnapping() )
return aPoint;
VECTOR2I nearest = AlignGrid( aPoint );
if( !m_auxAxis )
return nearest;
if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
nearest.x = m_auxAxis->x;
if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
nearest.y = m_auxAxis->y;
return nearest;
}
VECTOR2I EE_GRID_HELPER::AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg )
{
OPT_VECTOR2I pts[6];
if( !m_enableSnap )
return aPoint;
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D gridSize( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
pts[0] = aSeg.A;
pts[1] = aSeg.B;
pts[2] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, 0 ), nearest + VECTOR2I( 1, 0 ) ) );
pts[3] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( 0, -1 ), nearest + VECTOR2I( 0, 1 ) ) );
int min_d = std::numeric_limits<int>::max();
for( int i = 0; i < 4; i++ )
{
if( pts[i] && aSeg.Contains( *pts[i] ) )
{
int d = (*pts[i] - aPoint).EuclideanNorm();
if( d < min_d )
{
min_d = d;
nearest = *pts[i];
}
}
}
return nearest;
}
VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, int aLayer, VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, int aLayer,
const EE_SELECTION& aItems ) const EE_SELECTION& aItems )
{ {
@ -230,32 +103,6 @@ VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, int aLayer,
} }
std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
const EE_SELECTION& aSkip ) const
{
std::set<SCH_ITEM*> items;
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
KIGFX::VIEW* view = m_toolMgr->GetView();
view->Query( aArea, selectedItems );
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
{
SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
// The item must be visible and on an active layer
if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
items.insert ( item );
}
for( EDA_ITEM* skipItem : aSkip )
items.erase( static_cast<SCH_ITEM*>( skipItem ) );
return items;
}
VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, SCH_ITEM* aSkip ) VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, SCH_ITEM* aSkip )
{ {
EE_SELECTION skipItems; EE_SELECTION skipItems;
@ -380,7 +227,33 @@ SCH_ITEM* EE_GRID_HELPER::GetSnapped() const
if( !m_snapItem ) if( !m_snapItem )
return nullptr; return nullptr;
return m_snapItem->item; return static_cast<SCH_ITEM*>( m_snapItem->item );
}
std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
const EE_SELECTION& aSkipList ) const
{
std::set<SCH_ITEM*> items;
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
KIGFX::VIEW* view = m_toolMgr->GetView();
view->Query( aArea, selectedItems );
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
{
SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
// The item must be visible and on an active layer
if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
items.insert ( item );
}
for( EDA_ITEM* skipItem : aSkipList )
items.erase( static_cast<SCH_ITEM*>( skipItem ) );
return items;
} }
@ -422,12 +295,14 @@ EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int
for( ANCHOR& a : m_anchors ) for( ANCHOR& a : m_anchors )
{ {
SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
if( ( aFlags & a.flags ) != aFlags ) if( ( aFlags & a.flags ) != aFlags )
continue; continue;
if( aMatchLayer == LAYER_CONNECTABLE && !a.item->IsConnectable() ) if( aMatchLayer == LAYER_CONNECTABLE && !item->IsConnectable() )
continue; continue;
else if( aMatchLayer == LAYER_GRAPHICS && a.item->IsConnectable() ) else if( aMatchLayer == LAYER_GRAPHICS && item->IsConnectable() )
continue; continue;
double dist = a.Distance( aPos ); double dist = a.Distance( aPos );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 CERN * Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -23,26 +23,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/** #ifndef EE_GRID_HELPER_H
* EE_GRID_HELPER #define EE_GRID_HELPER_H
*
* A helper class for doing grid and object snapping.
*
* It shares its roots with PCBNew's GRID_HELPER, but uses the layers architecture to split
* connectable items from graphic items.
*/
#ifndef __GRID_HELPER_H
#define __GRID_HELPER_H
#include <vector>
#include <math/vector2d.h> #include <math/vector2d.h>
#include <origin_viewitem.h> #include <origin_viewitem.h>
#include <tool/grid_helper.h>
#include <ee_selection.h> #include <ee_selection.h>
class LSET;
class SCH_ITEM; class SCH_ITEM;
class SEG;
enum EE_GRID_HELPER_LAYERS : int enum EE_GRID_HELPER_LAYERS : int
@ -53,15 +42,11 @@ enum EE_GRID_HELPER_LAYERS : int
}; };
class EE_GRID_HELPER class EE_GRID_HELPER : public GRID_HELPER
{ {
public: public:
EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ); EE_GRID_HELPER( TOOL_MANAGER* aToolMgr );
~EE_GRID_HELPER();
VECTOR2I GetGrid() const;
VECTOR2I GetOrigin() const;
/** /**
* Function GetSnapped * Function GetSnapped
@ -72,70 +57,13 @@ public:
*/ */
SCH_ITEM* GetSnapped() const; SCH_ITEM* GetSnapped() const;
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
VECTOR2I Align( const VECTOR2I& aPoint ) const;
VECTOR2I AlignGrid( const VECTOR2I& aPoint ) const;
VECTOR2I AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, int aLayer, const EE_SELECTION& aItems ); VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, int aLayer, const EE_SELECTION& aItems );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, SCH_ITEM* aDraggedItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, SCH_ITEM* aDraggedItem );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, const EE_SELECTION& aSkip = {} ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, int aLayer, const EE_SELECTION& aSkip = {} );
void SetSkipPoint( const VECTOR2I& aPoint )
{
m_skipPoint = aPoint;
}
/**
* We clear the skip point by setting it to an unreachable position, thereby preventing matching
*/
void ClearSkipPoint()
{
m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
}
void SetSnap( bool aSnap ) { m_enableSnap = aSnap; }
void SetUseGrid( bool aSnapToGrid ) { m_enableGrid = aSnapToGrid; }
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
private: private:
enum ANCHOR_FLAGS { std::set<SCH_ITEM*> queryVisible( const BOX2I& aArea, const EE_SELECTION& aSkipList ) const;
CORNER = 1,
OUTLINE = 2,
SNAPPABLE = 4,
ORIGIN = 8,
VERTICAL = 16,
HORIZONTAL = 32
};
struct ANCHOR
{
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, SCH_ITEM* aItem = NULL ) :
pos( aPos ),
flags( aFlags ),
item( aItem )
{ };
VECTOR2I pos;
int flags;
SCH_ITEM* item;
double Distance( const VECTOR2I& aP ) const
{
return ( aP - pos ).EuclideanNorm();
}
};
std::set<SCH_ITEM*> queryVisible( const BOX2I& aArea, const EE_SELECTION& aSkip ) const;
void addAnchor( const VECTOR2I& aPos, int aFlags, SCH_ITEM* aItem )
{
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
}
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, int aMatchLayer ); ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, int aMatchLayer );
@ -148,27 +76,6 @@ private:
* @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not * @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
*/ */
void computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false ); void computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false );
void clearAnchors()
{
m_anchors.clear();
}
std::vector<ANCHOR> m_anchors;
TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis;
bool m_enableSnap; // Allow snapping to other items on the layers
bool m_enableGrid; // If true, allow snapping to grid
bool m_enableSnapLine; // Allow drawing lines from snap points
ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors
// (NULL if not snapped)
VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the source
// point
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
KIGFX::ORIGIN_VIEWITEM m_viewAxis;
}; };
#endif #endif

123
include/tool/grid_helper.h Normal file
View File

@ -0,0 +1,123 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
#ifndef GRID_HELPER_H
#define GRID_HELPER_H
#include <vector>
#include <math/vector2d.h>
#include <origin_viewitem.h>
class TOOL_MANAGER;
class EDA_ITEM;
class GRID_HELPER
{
public:
GRID_HELPER( TOOL_MANAGER* aToolMgr );
~GRID_HELPER();
VECTOR2I GetGrid() const;
VECTOR2I GetOrigin() const;
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
virtual VECTOR2I Align( const VECTOR2I& aPoint ) const;
VECTOR2I AlignGrid( const VECTOR2I& aPoint ) const;
void SetSkipPoint( const VECTOR2I& aPoint )
{
m_skipPoint = aPoint;
}
/**
* We clear the skip point by setting it to an unreachable position, thereby preventing matching
*/
void ClearSkipPoint()
{
m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
}
void SetSnap( bool aSnap ) { m_enableSnap = aSnap; }
void SetUseGrid( bool aSnapToGrid ) { m_enableGrid = aSnapToGrid; }
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
protected:
enum ANCHOR_FLAGS {
CORNER = 1,
OUTLINE = 2,
SNAPPABLE = 4,
ORIGIN = 8,
VERTICAL = 16,
HORIZONTAL = 32
};
struct ANCHOR
{
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, EDA_ITEM* aItem = NULL ) :
pos( aPos ),
flags( aFlags ),
item( aItem )
{ };
VECTOR2I pos;
int flags;
EDA_ITEM* item;
double Distance( const VECTOR2I& aP ) const
{
return ( aP - pos ).EuclideanNorm();
}
};
void addAnchor( const VECTOR2I& aPos, int aFlags, EDA_ITEM* aItem )
{
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
}
void clearAnchors()
{
m_anchors.clear();
}
protected:
std::vector<ANCHOR> m_anchors;
TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis;
bool m_enableSnap; // Allow snapping to other items on the layers
bool m_enableGrid; // If true, allow snapping to grid
bool m_enableSnapLine; // Allow drawing lines from snap points
ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors
// (NULL if not snapped)
VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the source
// point
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
KIGFX::ORIGIN_VIEWITEM m_viewAxis;
};
#endif

View File

@ -343,7 +343,7 @@ set( PCBNEW_CLASS_SRCS
tools/pcb_selection_tool.cpp tools/pcb_selection_tool.cpp
tools/pcb_tool_base.cpp tools/pcb_tool_base.cpp
tools/placement_tool.cpp tools/placement_tool.cpp
tools/point_editor.cpp tools/pcb_point_editor.cpp
tools/position_relative_tool.cpp tools/position_relative_tool.cpp
tools/tool_event_utils.cpp tools/tool_event_utils.cpp
tools/zone_create_helper.cpp tools/zone_create_helper.cpp

View File

@ -29,7 +29,7 @@
#include "tools/pcb_control.h" #include "tools/pcb_control.h"
#include "tools/pcb_picker_tool.h" #include "tools/pcb_picker_tool.h"
#include "tools/placement_tool.h" #include "tools/placement_tool.h"
#include "tools/point_editor.h" #include "tools/pcb_point_editor.h"
#include "tools/pcb_selection_tool.h" #include "tools/pcb_selection_tool.h"
#include <3d_viewer/eda_3d_viewer.h> #include <3d_viewer/eda_3d_viewer.h>
#include <bitmaps.h> #include <bitmaps.h>
@ -928,7 +928,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
m_toolManager->RegisterTool( new EDIT_TOOL ); m_toolManager->RegisterTool( new EDIT_TOOL );
m_toolManager->RegisterTool( new PAD_TOOL ); m_toolManager->RegisterTool( new PAD_TOOL );
m_toolManager->RegisterTool( new DRAWING_TOOL ); m_toolManager->RegisterTool( new DRAWING_TOOL );
m_toolManager->RegisterTool( new POINT_EDITOR ); m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
m_toolManager->RegisterTool( new PCB_CONTROL ); // copy/paste m_toolManager->RegisterTool( new PCB_CONTROL ); // copy/paste
m_toolManager->RegisterTool( new FOOTPRINT_EDITOR_CONTROL ); m_toolManager->RegisterTool( new FOOTPRINT_EDITOR_CONTROL );
m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL ); m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
@ -942,7 +942,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
m_toolManager->GetTool<EDIT_TOOL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<EDIT_TOOL>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<PAD_TOOL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<PAD_TOOL>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<DRAWING_TOOL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<DRAWING_TOOL>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<POINT_EDITOR>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<PCB_POINT_EDITOR>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<PCB_CONTROL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<PCB_CONTROL>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<PCB_PICKER_TOOL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<PCB_PICKER_TOOL>()->SetIsFootprintEditor( true );
m_toolManager->GetTool<POSITION_RELATIVE_TOOL>()->SetIsFootprintEditor( true ); m_toolManager->GetTool<POSITION_RELATIVE_TOOL>()->SetIsFootprintEditor( true );

View File

@ -59,7 +59,7 @@
#include <tool/zoom_tool.h> #include <tool/zoom_tool.h>
#include <tools/pcb_selection_tool.h> #include <tools/pcb_selection_tool.h>
#include <tools/pcb_picker_tool.h> #include <tools/pcb_picker_tool.h>
#include <tools/point_editor.h> #include <tools/pcb_point_editor.h>
#include <tools/edit_tool.h> #include <tools/edit_tool.h>
#include <tools/group_tool.h> #include <tools/group_tool.h>
#include <tools/drc_tool.h> #include <tools/drc_tool.h>
@ -473,7 +473,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL ); m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
m_toolManager->RegisterTool( new PAD_TOOL ); m_toolManager->RegisterTool( new PAD_TOOL );
m_toolManager->RegisterTool( new DRAWING_TOOL ); m_toolManager->RegisterTool( new DRAWING_TOOL );
m_toolManager->RegisterTool( new POINT_EDITOR ); m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
m_toolManager->RegisterTool( new PCB_CONTROL ); m_toolManager->RegisterTool( new PCB_CONTROL );
m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL ); m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL ); m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );

View File

@ -31,7 +31,7 @@ using namespace std::placeholders;
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
#include <bitmaps.h> #include <bitmaps.h>
#include <tools/grid_helper.h> #include <tools/pcb_grid_helper.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
@ -103,7 +103,7 @@ void TOOL_BASE::Reset( RESET_REASON aReason )
m_router->LoadSettings( settings->m_PnsSettings.get() ); m_router->LoadSettings( settings->m_PnsSettings.get() );
m_gridHelper = new GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() ); m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
} }

View File

@ -34,7 +34,7 @@
#include "pns_router.h" #include "pns_router.h"
class GRID_HELPER; class PCB_GRID_HELPER;
class PNS_KICAD_IFACE; class PNS_KICAD_IFACE;
class PNS_TUNE_STATUS_POPUP; class PNS_TUNE_STATUS_POPUP;
@ -73,7 +73,7 @@ protected:
ITEM* m_endItem; ITEM* m_endItem;
VECTOR2I m_endSnapPoint; VECTOR2I m_endSnapPoint;
GRID_HELPER* m_gridHelper; PCB_GRID_HELPER* m_gridHelper;
PNS_KICAD_IFACE* m_iface; PNS_KICAD_IFACE* m_iface;
ROUTER* m_router; ROUTER* m_router;

View File

@ -40,7 +40,7 @@ using namespace std::placeholders;
#include <tool/tool_menu.h> #include <tool/tool_menu.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <tools/pcb_selection_tool.h> #include <tools/pcb_selection_tool.h>
#include <tools/grid_helper.h> #include <tools/pcb_grid_helper.h>
#include "router_tool.h" #include "router_tool.h"
#include "pns_segment.h" #include "pns_segment.h"

View File

@ -30,7 +30,7 @@
#include <view/view.h> #include <view/view.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <tools/grid_helper.h> #include <tools/pcb_grid_helper.h>
#include <tools/pcb_selection_tool.h> #include <tools/pcb_selection_tool.h>
#include <tools/tool_event_utils.h> #include <tools/tool_event_utils.h>
#include <tools/zone_create_helper.h> #include <tools/zone_create_helper.h>
@ -643,7 +643,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
TOOL_EVENT originalEvent = aEvent; TOOL_EVENT originalEvent = aEvent;
DIMENSION_BASE* dimension = nullptr; DIMENSION_BASE* dimension = nullptr;
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings(); const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
@ -1159,7 +1159,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
return 0; return 0;
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
@ -1248,7 +1248,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
assert( shape == S_SEGMENT || shape == S_CIRCLE || shape == S_RECT ); assert( shape == S_SEGMENT || shape == S_CIRCLE || shape == S_RECT );
EDA_UNITS userUnits = m_frame->GetUserUnits(); EDA_UNITS userUnits = m_frame->GetUserUnits();
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
PCB_SHAPE*& graphic = *aGraphic; PCB_SHAPE*& graphic = *aGraphic;
m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() );
@ -1566,7 +1566,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
PCB_SELECTION preview; PCB_SELECTION preview;
m_view->Add( &preview ); m_view->Add( &preview );
m_view->Add( &arcAsst ); m_view->Add( &arcAsst );
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
@ -1860,7 +1860,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
bool started = false; bool started = false;
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
STATUS_TEXT_POPUP status( m_frame ); STATUS_TEXT_POPUP status( m_frame );
status.SetTextColor( wxColour( 255, 0, 0 ) ); status.SetTextColor( wxColour( 255, 0, 0 ) );
status.SetText( _( "Self-intersecting polygons are not allowed" ) ); status.SetText( _( "Self-intersecting polygons are not allowed" ) );
@ -2046,7 +2046,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
{ {
struct VIA_PLACER : public INTERACTIVE_PLACER_BASE struct VIA_PLACER : public INTERACTIVE_PLACER_BASE
{ {
GRID_HELPER m_gridHelper; PCB_GRID_HELPER m_gridHelper;
VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) : VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ) m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() )

View File

@ -42,7 +42,7 @@
#include <tools/edit_tool.h> #include <tools/edit_tool.h>
#include <tools/pcb_picker_tool.h> #include <tools/pcb_picker_tool.h>
#include <tools/tool_event_utils.h> #include <tools/tool_event_utils.h>
#include <tools/grid_helper.h> #include <tools/pcb_grid_helper.h>
#include <tools/pad_tool.h> #include <tools/pad_tool.h>
#include <pad_naming.h> #include <pad_naming.h>
#include <view/view_controls.h> #include <view/view_controls.h>
@ -398,7 +398,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
bool restore_state = false; bool restore_state = false;
VECTOR2I totalMovement; VECTOR2I totalMovement;
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent ); TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
VECTOR2I prevPos; VECTOR2I prevPos;
@ -1949,7 +1949,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent )
{ {
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint"; std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
CLIPBOARD_IO io; CLIPBOARD_IO io;
GRID_HELPER grid( m_toolMgr, getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
frame()->PushTool( tool ); frame()->PushTool( tool );
Activate(); Activate();

View File

@ -1,167 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@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
*/
#ifndef __GRID_HELPER_H
#define __GRID_HELPER_H
#include <vector>
#include <math/vector2d.h>
#include <core/optional.h>
#include <origin_viewitem.h>
#include <layers_id_colors_and_visibility.h>
class TOOL_MANAGER;
class GRID_HELPER {
public:
GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings );
~GRID_HELPER();
VECTOR2I GetGrid() const;
VECTOR2I GetOrigin() const;
/**
* Function GetSnapped
* If the GRID_HELPER has highlighted a snap point (target shown), this function
* will return a pointer to the item to which it snapped.
*
* @return NULL if not snapped. Pointer to snapped item otherwise
*/
BOARD_ITEM* GetSnapped() const;
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
VECTOR2I Align( const VECTOR2I& aPoint ) const;
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem );
VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
const std::vector<BOARD_ITEM*>& aSkip = {} );
void SetSkipPoint( const VECTOR2I& aPoint )
{
m_skipPoint = aPoint;
}
/**
* We clear the skip point by setting it to an unreachable position, thereby preventing matching
*/
void ClearSkipPoint()
{
m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
}
void SetSnap( bool aSnap )
{
m_enableSnap = aSnap;
}
void SetSnapLine( bool aSnap )
{
m_enableSnapLine = aSnap;
}
void SetUseGrid( bool aGrid = true )
{
m_enableGrid = aGrid;
}
private:
enum ANCHOR_FLAGS {
CORNER = 0x1,
OUTLINE = 0x2,
SNAPPABLE = 0x4,
ORIGIN = 0x8
};
struct ANCHOR
{
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ) :
pos( aPos ),
flags( aFlags ),
item( aItem )
{ };
VECTOR2I pos;
int flags;
BOARD_ITEM* item;
double Distance( const VECTOR2I& aP ) const
{
return ( aP - pos ).EuclideanNorm();
}
};
std::vector<ANCHOR> m_anchors;
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*>& aSkip ) const;
void addAnchor( const VECTOR2I& aPos, int aFlags, BOARD_ITEM* aItem )
{
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
}
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
/**
* computeAnchors inserts the local anchor points in to the grid helper for the specified
* board item, given the reference point and the direction of use for the point.
*
* @param aItem The board item for which to compute the anchors
* @param aRefPos The point for which to compute the anchors (if used by the component)
* @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
*/
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false );
void clearAnchors()
{
m_anchors.clear();
}
TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis;
bool m_enableSnap; // If true, allow snapping to other items on the layers
bool m_enableGrid; // If true, allow snapping to grid
bool m_enableSnapLine; // If true, allow drawing lines from snap points
ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors
// (NULL if not snapped)
VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the source point
MAGNETIC_SETTINGS* m_magneticSettings;
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
KIGFX::ORIGIN_VIEWITEM m_viewAxis;
};
#endif

View File

@ -1104,7 +1104,7 @@ TOOL_ACTION PCB_ACTIONS::distributeVertically( "pcbnew.AlignAndDistribute.distri
_( "Distributes selected items along the vertical axis" ), distribute_vertical_xpm ); _( "Distributes selected items along the vertical axis" ), distribute_vertical_xpm );
// POINT_EDITOR // PCB_POINT_EDITOR
// //
TOOL_ACTION PCB_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner", TOOL_ACTION PCB_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner",
AS_GLOBAL, AS_GLOBAL,

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 CERN * Copyright (C) 2014 CERN
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,8 +24,6 @@
*/ */
#include <functional> #include <functional>
using namespace std::placeholders;
#include <board.h> #include <board.h>
#include <dimension.h> #include <dimension.h>
#include <fp_shape.h> #include <fp_shape.h>
@ -39,26 +37,18 @@ using namespace std::placeholders;
#include <geometry/shape_simple.h> #include <geometry/shape_simple.h>
#include <macros.h> #include <macros.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
#include <math/vector2d.h>
#include <painter.h> #include <painter.h>
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/pcb_tool_base.h> #include <tools/pcb_tool_base.h>
#include <view/view.h> #include <view/view.h>
#include <view/view_controls.h> #include "pcb_grid_helper.h"
#include "grid_helper.h"
GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) : PCB_GRID_HELPER::PCB_GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) :
m_toolMgr( aToolMgr ), GRID_HELPER( aToolMgr ),
m_magneticSettings( aMagneticSettings ) m_magneticSettings( aMagneticSettings )
{ {
m_enableSnap = true;
m_enableGrid = true;
m_enableSnapLine = true;
m_snapItem = nullptr;
KIGFX::VIEW* view = m_toolMgr->GetView(); KIGFX::VIEW* view = m_toolMgr->GetView();
KIGFX::RENDER_SETTINGS* settings = view->GetPainter()->GetSettings(); KIGFX::RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
KIGFX::COLOR4D auxItemsColor = settings->GetLayerColor( LAYER_AUX_ITEMS ); KIGFX::COLOR4D auxItemsColor = settings->GetLayerColor( LAYER_AUX_ITEMS );
@ -85,68 +75,7 @@ GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSe
} }
GRID_HELPER::~GRID_HELPER() VECTOR2I PCB_GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
{
}
VECTOR2I GRID_HELPER::GetGrid() const
{
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetGridSize();
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
}
VECTOR2I GRID_HELPER::GetOrigin() const
{
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
return VECTOR2I( origin );
}
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
{
if( aEnable )
{
m_auxAxis = aOrigin;
m_viewAxis.SetPosition( wxPoint( aOrigin ) );
m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
}
else
{
m_auxAxis = OPT<VECTOR2I>();
m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
}
}
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
{
if( !m_enableGrid )
return aPoint;
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D grid( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
if( !m_auxAxis )
return nearest;
if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
nearest.x = m_auxAxis->x;
if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
nearest.y = m_auxAxis->y;
return nearest;
}
VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
{ {
OPT_VECTOR2I pts[6]; OPT_VECTOR2I pts[6];
@ -184,7 +113,7 @@ VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
} }
VECTOR2I GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc ) VECTOR2I PCB_GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc )
{ {
if( !m_enableSnap ) if( !m_enableSnap )
return aPoint; return aPoint;
@ -214,7 +143,8 @@ VECTOR2I GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc
} }
VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOARD_ITEM*>& aItems ) VECTOR2I PCB_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos,
std::vector<BOARD_ITEM*>& aItems )
{ {
clearAnchors(); clearAnchors();
@ -259,48 +189,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOA
} }
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea, VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem )
const std::vector<BOARD_ITEM*>& aSkip ) const
{
std::set<BOARD_ITEM*> items;
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
KIGFX::VIEW* view = m_toolMgr->GetView();
RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
bool isHighContrast = settings->GetHighContrast();
view->Query( aArea, selectedItems );
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
// If we are in the footprint editor, don't use the footprint itself
if( static_cast<PCB_TOOL_BASE*>( m_toolMgr->GetCurrentTool() )->IsFootprintEditor()
&& item->Type() == PCB_FOOTPRINT_T )
{
continue;
}
// The item must be visible and on an active layer
if( view->IsVisible( item )
&& ( !isHighContrast || activeLayers.count( it.second ) )
&& item->ViewGetLOD( it.second, view ) < view->GetScale() )
{
items.insert ( item );
}
}
for( BOARD_ITEM* skipItem : aSkip )
items.erase( skipItem );
return items;
}
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem )
{ {
LSET layers; LSET layers;
std::vector<BOARD_ITEM*> item; std::vector<BOARD_ITEM*> item;
@ -317,7 +206,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDrag
} }
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
const std::vector<BOARD_ITEM*>& aSkip ) const std::vector<BOARD_ITEM*>& aSkip )
{ {
// Tuning constant: snap radius in screen space // Tuning constant: snap radius in screen space
@ -403,16 +292,56 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
} }
BOARD_ITEM* GRID_HELPER::GetSnapped() const BOARD_ITEM* PCB_GRID_HELPER::GetSnapped() const
{ {
if( !m_snapItem ) if( !m_snapItem )
return nullptr; return nullptr;
return m_snapItem->item; return static_cast<BOARD_ITEM*>( m_snapItem->item );
} }
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom ) std::set<BOARD_ITEM*> PCB_GRID_HELPER::queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*>& aSkip ) const
{
std::set<BOARD_ITEM*> items;
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
KIGFX::VIEW* view = m_toolMgr->GetView();
RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
bool isHighContrast = settings->GetHighContrast();
view->Query( aArea, selectedItems );
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
// If we are in the footprint editor, don't use the footprint itself
if( static_cast<PCB_TOOL_BASE*>( m_toolMgr->GetCurrentTool() )->IsFootprintEditor()
&& item->Type() == PCB_FOOTPRINT_T )
{
continue;
}
// The item must be visible and on an active layer
if( view->IsVisible( item )
&& ( !isHighContrast || activeLayers.count( it.second ) )
&& item->ViewGetLOD( it.second, view ) < view->GetScale() )
{
items.insert ( item );
}
}
for( BOARD_ITEM* skipItem : aSkip )
items.erase( skipItem );
return items;
}
void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
{ {
VECTOR2I origin; VECTOR2I origin;
KIGFX::VIEW* view = m_toolMgr->GetView(); KIGFX::VIEW* view = m_toolMgr->GetView();
@ -749,7 +678,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
} }
GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags, PCB_GRID_HELPER::ANCHOR* PCB_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags,
LSET aMatchLayers ) LSET aMatchLayers )
{ {
double minDist = std::numeric_limits<double>::max(); double minDist = std::numeric_limits<double>::max();
@ -757,7 +686,9 @@ GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlag
for( ANCHOR& a : m_anchors ) for( ANCHOR& a : m_anchors )
{ {
if( ( aMatchLayers & a.item->GetLayerSet() ) == 0 ) BOARD_ITEM* item = static_cast<BOARD_ITEM*>( a.item );
if( ( aMatchLayers & item->GetLayerSet() ) == 0 )
continue; continue;
if( ( aFlags & a.flags ) != aFlags ) if( ( aFlags & a.flags ) != aFlags )

View File

@ -0,0 +1,87 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@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
*/
#ifndef PCB_GRID_HELPER_H
#define PCB_GRID_HELPER_H
#include <vector>
#include <tool/grid_helper.h>
class TOOL_MANAGER;
class PCB_GRID_HELPER : public GRID_HELPER
{
public:
PCB_GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings );
/**
* Function GetSnapped
* If the PCB_GRID_HELPER has highlighted a snap point (target shown), this function
* will return a pointer to the item to which it snapped.
*
* @return NULL if not snapped. Pointer to snapped item otherwise
*/
BOARD_ITEM* GetSnapped() const;
VECTOR2I Align( const VECTOR2I& aPoint ) const override
{
if( !m_enableGrid )
return aPoint;
return GRID_HELPER::Align( aPoint );
}
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem );
VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
const std::vector<BOARD_ITEM*>& aSkip = {} );
private:
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*>& aSkip ) const;
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
/**
* computeAnchors inserts the local anchor points in to the grid helper for the specified
* board item, given the reference point and the direction of use for the point.
*
* @param aItem The board item for which to compute the anchors
* @param aRefPos The point for which to compute the anchors (if used by the component)
* @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
*/
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false );
private:
MAGNETIC_SETTINGS* m_magneticSettings;
};
#endif

View File

@ -25,7 +25,7 @@
#include "pcb_picker_tool.h" #include "pcb_picker_tool.h"
#include "pcb_actions.h" #include "pcb_actions.h"
#include "grid_helper.h" #include "pcb_grid_helper.h"
#include <view/view_controls.h> #include <view/view_controls.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include "pcb_selection_tool.h" #include "pcb_selection_tool.h"
@ -42,7 +42,7 @@ int PCB_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
GRID_HELPER grid( m_toolMgr, frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, frame->GetMagneticItemsSettings() );
int finalize_state = WAIT_CANCEL; int finalize_state = WAIT_CANCEL;
std::string tool = *aEvent.Parameter<std::string*>(); std::string tool = *aEvent.Parameter<std::string*>();

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2019 CERN * Copyright (C) 2013-2021 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -25,16 +25,14 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
using namespace std::placeholders; using namespace std::placeholders;
#include <advanced_config.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/seg.h> #include <geometry/seg.h>
#include <confirm.h> #include <confirm.h>
#include "pcb_actions.h" #include "pcb_actions.h"
#include "pcb_selection_tool.h" #include "pcb_selection_tool.h"
#include "point_editor.h" #include "pcb_point_editor.h"
#include "grid_helper.h" #include "pcb_grid_helper.h"
#include <board_commit.h> #include <board_commit.h>
#include <bitmaps.h> #include <bitmaps.h>
#include <status_popup.h> #include <status_popup.h>
@ -88,7 +86,7 @@ enum DIMENSION_POINTS
DIM_CROSSBAREND, DIM_CROSSBAREND,
}; };
POINT_EDITOR::POINT_EDITOR() : PCB_POINT_EDITOR::PCB_POINT_EDITOR() :
PCB_TOOL_BASE( "pcbnew.PointEditor" ), PCB_TOOL_BASE( "pcbnew.PointEditor" ),
m_selectionTool( nullptr ), m_selectionTool( nullptr ),
m_editedPoint( nullptr ), m_editedPoint( nullptr ),
@ -101,7 +99,7 @@ POINT_EDITOR::POINT_EDITOR() :
} }
void POINT_EDITOR::Reset( RESET_REASON aReason ) void PCB_POINT_EDITOR::Reset( RESET_REASON aReason )
{ {
m_refill = false; m_refill = false;
m_editPoints.reset(); m_editPoints.reset();
@ -114,7 +112,7 @@ void POINT_EDITOR::Reset( RESET_REASON aReason )
} }
bool POINT_EDITOR::Init() bool PCB_POINT_EDITOR::Init()
{ {
// Find the selection tool, so they can cooperate // Find the selection tool, so they can cooperate
m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>(); m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
@ -122,15 +120,15 @@ bool POINT_EDITOR::Init()
wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" ); wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
auto& menu = m_selectionTool->GetToolMenu().GetMenu(); auto& menu = m_selectionTool->GetToolMenu().GetMenu();
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, POINT_EDITOR::addCornerCondition ); menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, PCB_POINT_EDITOR::addCornerCondition );
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner, menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner,
std::bind( &POINT_EDITOR::removeCornerCondition, this, _1 ) ); std::bind( &PCB_POINT_EDITOR::removeCornerCondition, this, _1 ) );
return true; return true;
} }
void POINT_EDITOR::buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, void PCB_POINT_EDITOR::buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
const SHAPE_POLY_SET* aOutline ) const SHAPE_POLY_SET* aOutline )
{ {
int cornersCount = aOutline->TotalVertices(); int cornersCount = aOutline->TotalVertices();
@ -164,7 +162,7 @@ void POINT_EDITOR::buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
} }
std::shared_ptr<EDIT_POINTS> POINT_EDITOR::makePoints( EDA_ITEM* aItem ) std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
{ {
std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem ); std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
@ -345,7 +343,7 @@ std::shared_ptr<EDIT_POINTS> POINT_EDITOR::makePoints( EDA_ITEM* aItem )
} }
void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) void PCB_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
{ {
EDIT_POINT* point; EDIT_POINT* point;
EDIT_POINT* hovered = nullptr; EDIT_POINT* hovered = nullptr;
@ -386,7 +384,7 @@ void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
} }
int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
{ {
if( !m_selectionTool || aEvent.Matches( EVENTS::InhibitSelectionEditing ) ) if( !m_selectionTool || aEvent.Matches( EVENTS::InhibitSelectionEditing ) )
return 0; return 0;
@ -404,7 +402,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
controls->ShowCursor( true ); controls->ShowCursor( true );
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
if( !item ) if( !item )
@ -691,7 +689,7 @@ static void pinEditedCorner( int aEditedPointIndex, int aMinWidth, int aMinHeigh
} }
void POINT_EDITOR::editArcEndpointKeepShape( PCB_SHAPE* aArc, VECTOR2I aStart, VECTOR2I aMid, void PCB_POINT_EDITOR::editArcEndpointKeepShape( PCB_SHAPE* aArc, VECTOR2I aStart, VECTOR2I aMid,
VECTOR2I aEnd, const VECTOR2I aCursor ) const VECTOR2I aEnd, const VECTOR2I aCursor ) const
{ {
VECTOR2I diff; VECTOR2I diff;
@ -707,8 +705,8 @@ void POINT_EDITOR::editArcEndpointKeepShape( PCB_SHAPE* aArc, VECTOR2I aStart, V
} }
void POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart, void PCB_POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
VECTOR2I aMid, VECTOR2I aEnd, VECTOR2I aStart, VECTOR2I aMid, VECTOR2I aEnd,
const VECTOR2I aCursor ) const const VECTOR2I aCursor ) const
{ {
bool clockwise; bool clockwise;
@ -784,8 +782,9 @@ void POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
} }
void POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart, void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const VECTOR2I aMid, VECTOR2I aEnd,
const VECTOR2I aCursor ) const
{ {
// Now, update the edit point position // Now, update the edit point position
// Express the point in a cercle-centered coordinate system. // Express the point in a cercle-centered coordinate system.
@ -842,7 +841,7 @@ void POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECT
} }
void POINT_EDITOR::editArcMidKeepEndpoints( PCB_SHAPE* aArc, VECTOR2I aStart, VECTOR2I aEnd, void PCB_POINT_EDITOR::editArcMidKeepEndpoints( PCB_SHAPE* aArc, VECTOR2I aStart, VECTOR2I aEnd,
const VECTOR2I aCursor ) const const VECTOR2I aCursor ) const
{ {
// Let 'm' be the middle point of the chord between the start and end points // Let 'm' be the middle point of the chord between the start and end points
@ -859,7 +858,7 @@ void POINT_EDITOR::editArcMidKeepEndpoints( PCB_SHAPE* aArc, VECTOR2I aStart, VE
} }
void POINT_EDITOR::updateItem() const void PCB_POINT_EDITOR::updateItem() const
{ {
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
@ -1314,7 +1313,7 @@ void POINT_EDITOR::updateItem() const
} }
void POINT_EDITOR::finishItem() void PCB_POINT_EDITOR::finishItem()
{ {
auto item = m_editPoints->GetParent(); auto item = m_editPoints->GetParent();
@ -1331,7 +1330,7 @@ void POINT_EDITOR::finishItem()
} }
bool POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const bool PCB_POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
{ {
bool valid = !aPoly.IsSelfIntersecting(); bool valid = !aPoly.IsSelfIntersecting();
@ -1353,7 +1352,7 @@ bool POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
} }
void POINT_EDITOR::updatePoints() void PCB_POINT_EDITOR::updatePoints()
{ {
if( !m_editPoints ) if( !m_editPoints )
return; return;
@ -1575,7 +1574,7 @@ void POINT_EDITOR::updatePoints()
} }
void POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint ) void PCB_POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
@ -1597,7 +1596,7 @@ void POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
} }
void POINT_EDITOR::setAltConstraint( bool aEnabled ) void PCB_POINT_EDITOR::setAltConstraint( bool aEnabled )
{ {
if( aEnabled ) if( aEnabled )
{ {
@ -1636,7 +1635,7 @@ void POINT_EDITOR::setAltConstraint( bool aEnabled )
} }
EDIT_POINT POINT_EDITOR::get45DegConstrainer() const EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const
{ {
EDA_ITEM* item = m_editPoints->GetParent(); EDA_ITEM* item = m_editPoints->GetParent();
@ -1691,7 +1690,7 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const
} }
bool POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem ) bool PCB_POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem )
{ {
const auto type = aItem.Type(); const auto type = aItem.Type();
@ -1709,7 +1708,7 @@ bool POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem )
} }
bool POINT_EDITOR::addCornerCondition( const SELECTION& aSelection ) bool PCB_POINT_EDITOR::addCornerCondition( const SELECTION& aSelection )
{ {
if( aSelection.Size() != 1 ) if( aSelection.Size() != 1 )
return false; return false;
@ -1736,7 +1735,7 @@ findVertex( SHAPE_POLY_SET& aPolySet, const EDIT_POINT& aPoint )
} }
bool POINT_EDITOR::removeCornerCondition( const SELECTION& ) bool PCB_POINT_EDITOR::removeCornerCondition( const SELECTION& )
{ {
if( !m_editPoints || !m_editedPoint ) if( !m_editPoints || !m_editedPoint )
return false; return false;
@ -1780,7 +1779,7 @@ bool POINT_EDITOR::removeCornerCondition( const SELECTION& )
} }
int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
{ {
if( !m_editPoints ) if( !m_editPoints )
return 0; return 0;
@ -1911,7 +1910,7 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
} }
int POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent ) int PCB_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
{ {
if( !m_editPoints || !m_editedPoint ) if( !m_editPoints || !m_editedPoint )
return 0; return 0;
@ -1987,27 +1986,27 @@ int POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
} }
int POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent ) int PCB_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent )
{ {
updatePoints(); updatePoints();
return 0; return 0;
} }
int POINT_EDITOR::changeEditMethod( const TOOL_EVENT& aEvent ) int PCB_POINT_EDITOR::changeEditMethod( const TOOL_EVENT& aEvent )
{ {
m_altEditMethod = !m_altEditMethod; m_altEditMethod = !m_altEditMethod;
return 0; return 0;
} }
void POINT_EDITOR::setTransitions() void PCB_POINT_EDITOR::setTransitions()
{ {
Go( &POINT_EDITOR::OnSelectionChange, ACTIONS::activatePointEditor.MakeEvent() ); Go( &PCB_POINT_EDITOR::OnSelectionChange, ACTIONS::activatePointEditor.MakeEvent() );
Go( &POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() ); Go( &PCB_POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() );
Go( &POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() ); Go( &PCB_POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() );
Go( &POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified ); Go( &PCB_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified );
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::SelectedEvent ); Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::SelectedEvent );
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::UnselectedEvent ); Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::UnselectedEvent );
Go( &POINT_EDITOR::changeEditMethod, ACTIONS::changeEditMethod.MakeEvent() ); Go( &PCB_POINT_EDITOR::changeEditMethod, ACTIONS::changeEditMethod.MakeEvent() );
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::InhibitSelectionEditing ); Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::InhibitSelectionEditing );
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::UninhibitSelectionEditing ); Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::UninhibitSelectionEditing );
} }

View File

@ -22,8 +22,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef POINT_EDITOR_H #ifndef PCB_POINT_EDITOR_H
#define POINT_EDITOR_H #define PCB_POINT_EDITOR_H
#include <tool/tool_interactive.h> #include <tool/tool_interactive.h>
#include "tool/edit_points.h" #include "tool/edit_points.h"
@ -36,14 +36,14 @@ class PCB_SELECTION_TOOL;
class SHAPE_POLY_SET; class SHAPE_POLY_SET;
/** /**
* POINT_EDITOR * PCB_POINT_EDITOR
* *
* Tool that displays edit points allowing to modify items by dragging the points. * Tool that displays edit points allowing to modify items by dragging the points.
*/ */
class POINT_EDITOR : public PCB_TOOL_BASE class PCB_POINT_EDITOR : public PCB_TOOL_BASE
{ {
public: public:
POINT_EDITOR(); PCB_POINT_EDITOR();
/// @copydoc TOOL_INTERACTIVE::Reset() /// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override; void Reset( RESET_REASON aReason ) override;

View File

@ -27,7 +27,7 @@
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
#include <preview_items/ruler_item.h> #include <preview_items/ruler_item.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tools/grid_helper.h> #include <tools/pcb_grid_helper.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <tools/pcb_viewer_tools.h> #include <tools/pcb_viewer_tools.h>
#include <view/view_controls.h> #include <view/view_controls.h>
@ -215,7 +215,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
view.Add( &ruler ); view.Add( &ruler );
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );
GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
bool originSet = false; bool originSet = false;