Commit 3927c667 authored by Maciej Suminski's avatar Maciej Suminski

Added documentation. Moved some functions from .h to .cpp files.

parent 88a0311a
......@@ -29,6 +29,17 @@
#include <class_drawsegment.h>
bool EDIT_POINT::WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const
{
// Corners of the square
VECTOR2I topLeft = GetPosition() - aSize;
VECTOR2I bottomRight = GetPosition() + aSize;
return ( aPoint.x > topLeft.x && aPoint.y > topLeft.y &&
aPoint.x < bottomRight.x && aPoint.y < bottomRight.y );
}
EDIT_POINTS::EDIT_POINTS( EDA_ITEM* aParent ) :
EDA_ITEM( NOT_USED ), m_parent( aParent )
{
......@@ -61,6 +72,62 @@ EDIT_POINT* EDIT_POINTS::FindPoint( const VECTOR2I& aLocation )
}
EDIT_POINT* EDIT_POINTS::Previous( const EDIT_POINT& aPoint )
{
for( unsigned int i = 0; i < m_points.size(); ++i )
{
if( m_points[i] == aPoint )
{
if( i == 0 )
return &m_points[m_points.size() - 1];
else
return &m_points[i - 1];
}
}
for( unsigned int i = 0; i < m_lines.size(); ++i )
{
if( m_lines[i] == aPoint )
{
if( i == 0 )
return &m_lines[m_lines.size() - 1];
else
return &m_lines[i - 1];
}
}
return NULL;
}
EDIT_POINT* EDIT_POINTS::Next( const EDIT_POINT& aPoint )
{
for( unsigned int i = 0; i < m_points.size(); ++i )
{
if( m_points[i] == aPoint )
{
if( i == m_points.size() - 1 )
return &m_points[0];
else
return &m_points[i + 1];
}
}
for( unsigned int i = 0; i < m_lines.size(); ++i )
{
if( m_lines[i] == aPoint )
{
if( i == m_lines.size() - 1 )
return &m_lines[0];
else
return &m_lines[i + 1];
}
}
return NULL;
}
void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const
{
aGal->SetFillColor( KIGFX::COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
......@@ -79,3 +146,32 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const
aGal->PopDepth();
}
void EPC_45DEGREE::Apply()
{
// Current line vector
VECTOR2I lineVector( m_constrained.GetPosition() - m_constrainer.GetPosition() );
double angle = lineVector.Angle();
// Find the closest angle, which is a multiple of 45 degrees
double newAngle = round( angle / ( M_PI / 4.0 ) ) * M_PI / 4.0;
VECTOR2I newLineVector = lineVector.Rotate( newAngle - angle );
m_constrained.SetPosition( m_constrainer.GetPosition() + newLineVector );
}
void EPC_CIRCLE::Apply()
{
VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition();
VECTOR2I centerToPoint = m_constrained.GetPosition() - m_center.GetPosition();
int radius = centerToEnd.EuclideanNorm();
double angle = centerToPoint.Angle();
VECTOR2I newLine( radius, 0 );
newLine = newLine.Rotate( angle );
m_constrained.SetPosition( m_center.GetPosition() + newLine );
}
This diff is collapsed.
......@@ -159,6 +159,7 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
KIGFX::VIEW* view = getView();
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
EDA_ITEM* item = selection.items.GetPickedItem( 0 );
EDIT_POINT constrainer( VECTOR2I( 0, 0 ) );
m_editPoints = EDIT_POINTS_FACTORY::Make( item );
if( !m_editPoints )
......@@ -220,7 +221,7 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
if( !m_dragPoint->IsConstrained() )
{
// Find a proper constraining point for 45 degrees mode
EDIT_POINT constrainer = get45DegConstrainer();
constrainer = get45DegConstrainer();
m_dragPoint->SetConstraint( new EPC_45DEGREE( *m_dragPoint, constrainer ) );
}
}
......
......@@ -37,7 +37,6 @@ class SELECTION_TOOL;
*
* Tool that displays edit points allowing to modify items by dragging the points.
*/
class POINT_EDITOR : public TOOL_INTERACTIVE
{
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment