Added EC_SNAPLINE to make possible snapping EDIT_LINES by their ends rather than by its center.
This commit is contained in:
parent
23392ce8c9
commit
5de41eabd1
|
@ -131,8 +131,8 @@ EC_CONVERGING::~EC_CONVERGING()
|
|||
void EC_CONVERGING::Apply( EDIT_LINE& aHandle )
|
||||
{
|
||||
// The dragged segment endpoints
|
||||
EDIT_POINT& origin = m_constrained.GetOrigin();
|
||||
EDIT_POINT& end = m_constrained.GetEnd();
|
||||
EDIT_POINT& origin = aHandle.GetOrigin();
|
||||
EDIT_POINT& end = aHandle.GetEnd();
|
||||
|
||||
if( m_colinearConstraint )
|
||||
{
|
||||
|
@ -173,3 +173,17 @@ void EC_CONVERGING::Apply( EDIT_LINE& aHandle )
|
|||
end.SetPosition( *originEndIntersect );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EC_SNAPLINE::EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun ) :
|
||||
EDIT_CONSTRAINT<EDIT_LINE>( aLine ), m_snapFun( aSnapFun )
|
||||
{}
|
||||
|
||||
|
||||
void EC_SNAPLINE::Apply( EDIT_LINE& aHandle )
|
||||
{
|
||||
VECTOR2D delta = aHandle.GetEnd().GetPosition() - aHandle.GetOrigin().GetPosition();
|
||||
|
||||
aHandle.GetOrigin().SetPosition( m_snapFun( aHandle.GetOrigin().GetPosition() ) );
|
||||
aHandle.GetEnd().SetPosition( aHandle.GetOrigin().GetPosition() + delta );
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define EDIT_CONSTRAINTS_H_
|
||||
|
||||
#include <math/vector2d.h>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
class EDIT_POINT;
|
||||
class EDIT_LINE;
|
||||
|
@ -236,4 +237,31 @@ private:
|
|||
VECTOR2I m_draggedVector;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class EC_SNAPLINE
|
||||
*
|
||||
* EDIT_CONSTRAINT for a EDIT_LINE, one of the ends is snapped to a spot determined by a
|
||||
* transform function passed as parameter (e.g. it can be snapped to a grid), instead of having
|
||||
* the line center snapped to a point.
|
||||
*/
|
||||
class EC_SNAPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
|
||||
{
|
||||
public:
|
||||
///> Typedef for a function that determines snapping point.
|
||||
typedef boost::function<VECTOR2D (const VECTOR2D&)> V2D_TRANSFORM_FUN;
|
||||
|
||||
EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun );
|
||||
|
||||
virtual ~EC_SNAPLINE()
|
||||
{}
|
||||
|
||||
///> @copydoc EDIT_CONSTRAINT::Apply()
|
||||
virtual void Apply( EDIT_LINE& aHandle );
|
||||
|
||||
private:
|
||||
///> Function that determines snapping point.
|
||||
V2D_TRANSFORM_FUN m_snapFun;
|
||||
};
|
||||
|
||||
#endif /* EDIT_CONSTRAINTS_H_ */
|
||||
|
|
|
@ -418,15 +418,25 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Function Size()
|
||||
* Function PointsSize()
|
||||
*
|
||||
* Returns number of stored points.
|
||||
* Returns number of stored EDIT_POINTs.
|
||||
*/
|
||||
unsigned int Size() const
|
||||
unsigned int PointsSize() const
|
||||
{
|
||||
return m_points.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function LinesSize()
|
||||
*
|
||||
* Returns number of stored EDIT_LINEs.
|
||||
*/
|
||||
unsigned int LinesSize() const
|
||||
{
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
///> @copydoc VIEW_ITEM::ViewBBox()
|
||||
virtual const BOX2I ViewBBox() const
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <tool/tool_manager.h>
|
||||
#include <view/view_controls.h>
|
||||
|
@ -64,16 +65,11 @@ enum DIMENSION_POINTS
|
|||
DIM_FEATUREDO,
|
||||
};
|
||||
|
||||
/**
|
||||
* Class POINT_EDITOR
|
||||
*
|
||||
* Tool that displays edit points allowing to modify items by dragging the points.
|
||||
*/
|
||||
|
||||
class EDIT_POINTS_FACTORY
|
||||
{
|
||||
public:
|
||||
static boost::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem )
|
||||
static boost::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem, KIGFX::GAL* aGal )
|
||||
{
|
||||
boost::shared_ptr<EDIT_POINTS> points = boost::make_shared<EDIT_POINTS>( aItem );
|
||||
|
||||
|
@ -126,10 +122,18 @@ public:
|
|||
// Lines have to be added after creating edit points,
|
||||
// as they use EDIT_POINT references
|
||||
for( int i = 0; i < cornersCount - 1; ++i )
|
||||
{
|
||||
points->AddLine( points->Point( i ), points->Point( i + 1 ) );
|
||||
points->Line( i ).SetConstraint(
|
||||
new EC_SNAPLINE( points->Line( i ),
|
||||
boost::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
|
||||
}
|
||||
|
||||
// The last missing line, connecting the last and the first polygon point
|
||||
points->AddLine( points->Point( cornersCount - 1 ), points->Point( 0 ) );
|
||||
points->Line( points->LinesSize() - 1 ).SetConstraint(
|
||||
new EC_SNAPLINE( points->Line( points->LinesSize() - 1 ),
|
||||
boost::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -208,7 +212,7 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
|
|||
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
||||
EDA_ITEM* item = selection.items.GetPickedItem( 0 );
|
||||
|
||||
m_editPoints = EDIT_POINTS_FACTORY::Make( item );
|
||||
m_editPoints = EDIT_POINTS_FACTORY::Make( item, m_toolMgr->GetView()->GetGAL() );
|
||||
if( !m_editPoints )
|
||||
{
|
||||
setTransitions();
|
||||
|
|
Loading…
Reference in New Issue