From e6a7ff3c34cecaf76cd61b83f2688264a6213fca Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 18 Mar 2014 16:55:06 +0100 Subject: [PATCH] Isolated EDIT_CONSTRAINTs to different .cpp/.h files. --- pcbnew/CMakeLists.txt | 1 + pcbnew/tools/edit_constraints.cpp | 175 +++++++++++++++++++++ pcbnew/tools/edit_constraints.h | 242 ++++++++++++++++++++++++++++++ pcbnew/tools/edit_points.cpp | 135 +---------------- pcbnew/tools/edit_points.h | 225 +-------------------------- 5 files changed, 420 insertions(+), 358 deletions(-) create mode 100644 pcbnew/tools/edit_constraints.cpp create mode 100644 pcbnew/tools/edit_constraints.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 60deda1c4f..dee4a0af07 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -256,6 +256,7 @@ set( PCBNEW_CLASS_SRCS tools/selection_area.cpp tools/bright_box.cpp tools/edit_points.cpp + tools/edit_constraints.cpp tools/point_editor.cpp tools/drawing_tool.cpp tools/edit_tool.cpp diff --git a/pcbnew/tools/edit_constraints.cpp b/pcbnew/tools/edit_constraints.cpp new file mode 100644 index 0000000000..91e14ea82d --- /dev/null +++ b/pcbnew/tools/edit_constraints.cpp @@ -0,0 +1,175 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * @author Maciej Suminski + * + * 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 "edit_constraints.h" +#include "edit_points.h" + +#include + +void EC_VERTICAL::Apply( EDIT_POINT& aHandle ) +{ + VECTOR2I point = aHandle.GetPosition(); + point.x = m_constrainer.GetPosition().x; + aHandle.SetPosition( point ); +} + + +void EC_HORIZONTAL::Apply( EDIT_POINT& aHandle ) +{ + VECTOR2I point = aHandle.GetPosition(); + point.y = m_constrainer.GetPosition().y; + aHandle.SetPosition( point ); +} + + +void EC_45DEGREE::Apply( EDIT_POINT& aHandle ) +{ + // Current line vector + VECTOR2I lineVector( aHandle.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 ); + + aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector ); +} + + +EC_LINE::EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : + EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) +{ + m_line = m_constrained.GetPosition() - m_constrainer.GetPosition(); +} + + +void EC_LINE::Apply( EDIT_POINT& aHandle ) +{ + SEG main( m_constrainer.GetPosition(), m_constrainer.GetPosition() + m_line ); + SEG projection( aHandle.GetPosition(), aHandle.GetPosition() + m_line.Perpendicular() ); + + if( OPT_VECTOR2I intersect = projection.IntersectLines( main ) ) + aHandle.SetPosition( *intersect ); +} + + +void EC_CIRCLE::Apply( EDIT_POINT& aHandle ) +{ + VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition(); + VECTOR2I centerToPoint = aHandle.GetPosition() - m_center.GetPosition(); + + int radius = centerToEnd.EuclideanNorm(); + double angle = centerToPoint.Angle(); + + VECTOR2I newLine( radius, 0 ); + newLine = newLine.Rotate( angle ); + + aHandle.SetPosition( m_center.GetPosition() + newLine ); +} + + +EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : + EDIT_CONSTRAINT( aLine.GetOrigin() ), + m_colinearConstraint( NULL ), m_line( aLine ), m_editPoints( aPoints ) +{ + // Dragged segment endings + EDIT_POINT& origin = aLine.GetOrigin(); + EDIT_POINT& end = aLine.GetEnd(); + + // Previous and next points, to make constraining lines (adjacent to the dragged line) + EDIT_POINT& prevOrigin = *aPoints.Previous( origin ); + EDIT_POINT& nextEnd = *aPoints.Next( end ); + + // Constraints for segments adjacent to the dragged one + m_originSideConstraint = new EC_LINE( origin, prevOrigin ); + m_endSideConstraint = new EC_LINE( end, nextEnd ); + + // Store the current vector of the line + m_draggedVector = end.GetPosition() - origin.GetPosition(); + + // Check for colinearity + SEG originSide( origin.GetPosition(), prevOrigin.GetPosition() ); + SEG endSide( end.GetPosition(), nextEnd.GetPosition() ); + SEG dragged( origin.GetPosition(), end.GetPosition() ); + + if( dragged.Collinear( originSide ) ) + m_colinearConstraint = m_originSideConstraint; + else if( dragged.Collinear( endSide ) ) + m_colinearConstraint = m_endSideConstraint; +} + + +EC_CONVERGING::~EC_CONVERGING() +{ + delete m_originSideConstraint; + delete m_endSideConstraint; + // m_colinearConstraint should not be freed, it is a pointer to one of the above +} + + +void EC_CONVERGING::Apply( EDIT_POINT& aHandle ) +{ + // The dragged segment endpoints + EDIT_POINT& origin = m_line.GetOrigin(); + EDIT_POINT& end = m_line.GetEnd(); + + if( m_colinearConstraint ) + { + m_colinearConstraint->Apply( origin ); + m_colinearConstraint->Apply( end ); + } + + // The dragged segment + SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector ); + + // Do not allow points on the adjacent segments move freely + m_originSideConstraint->Apply(); + m_endSideConstraint->Apply(); + + EDIT_POINT& prevOrigin = *m_editPoints.Previous( origin ); + EDIT_POINT& nextEnd = *m_editPoints.Next( end ); + + // Two segments adjacent to the dragged segment + SEG originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() ); + SEG endSide = SEG( end.GetPosition(), nextEnd.GetPosition() ); + + // First intersection point (dragged segment against origin side) + if( OPT_VECTOR2I originIntersect = dragged.IntersectLines( originSide ) ) + origin.SetPosition( *originIntersect ); + + // Second intersection point (dragged segment against end side) + if( OPT_VECTOR2I endIntersect = dragged.IntersectLines( endSide ) ) + end.SetPosition( *endIntersect ); + + // Check if adjacent segments intersect (did we dragged the line to the point that it may + // create a selfintersecting polygon?) + originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() ); + endSide = SEG( end.GetPosition(), nextEnd.GetPosition() ); + + if( OPT_VECTOR2I originEndIntersect = endSide.Intersect( originSide ) ) + { + origin.SetPosition( *originEndIntersect ); + end.SetPosition( *originEndIntersect ); + } +} diff --git a/pcbnew/tools/edit_constraints.h b/pcbnew/tools/edit_constraints.h new file mode 100644 index 0000000000..b26c4f69f7 --- /dev/null +++ b/pcbnew/tools/edit_constraints.h @@ -0,0 +1,242 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * @author Maciej Suminski + * + * 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 EDIT_CONSTRAINTS_H_ +#define EDIT_CONSTRAINTS_H_ + +#include + +class EDIT_POINT; +class EDIT_LINE; +class EDIT_POINTS; + +/** + * Class EDIT_CONSTRAINT + * + * Allows to describe constraints between two edit handles. After the constrained handle is changed, + * Apply() has to be called to fix its coordinates according to the implemented constraint. + */ +template +class EDIT_CONSTRAINT +{ +public: + /** + * Constructor + * + * @param aConstrained is EDIT_POINT to which the constraint is applied. + */ + EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {}; + + virtual ~EDIT_CONSTRAINT() {}; + + /** + * Function Apply() + * + * Corrects coordinates of the constrained edit handle. + */ + virtual void Apply( EDIT_TYPE& aHandle ) = 0; + + /** + * Function Apply() + * + * Corrects coordinates of the constrained edit handle. + */ + void Apply() + { + Apply( m_constrained ); + } + +protected: + EDIT_TYPE& m_constrained; ///< Point that is constrained by rules implemented by Apply() +}; + + +/** + * Class EC_VERTICAL. + * + * EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate. + */ +class EC_VERTICAL : public EDIT_CONSTRAINT +{ +public: + /** + * Constructor. + * + * @param aConstrained is the point that is put under constrain. + * @param aConstrainer is the point that is the source of the constrain. + */ + EC_VERTICAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : + EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) + {} + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. +}; + + +/** + * Class EC_HORIZONTAL. + * + * EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate. + */ +class EC_HORIZONTAL : public EDIT_CONSTRAINT +{ +public: + /** + * Constructor. + * + * @param aConstrained is the point that is put under constrain. + * @param aConstrainer is the point that is the source of the constrain. + */ + EC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : + EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) + {} + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. +}; + + +/** + * Class EC_45DEGREE + * + * EDIT_CONSTRAINT that imposes a constraint that two to be located at angle of 45 degree + * multiplicity. + */ +class EC_45DEGREE : public EDIT_CONSTRAINT +{ +public: + /** + * Constructor. + * + * @param aConstrained is the point that is put under constrain. + * @param aConstrainer is the point that is the source of the constrain. + */ + EC_45DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : + EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) + {} + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. +}; + + +/** + * Class EC_LINE + * + * EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined + * by 2 points). + */ +class EC_LINE : public EDIT_CONSTRAINT +{ +public: + EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ); + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. + VECTOR2I m_line; ///< Vector representing the constraining line. +}; + + +/** + * Class EC_CIRCLE. + * + * EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle. + */ +class EC_CIRCLE : public EDIT_CONSTRAINT +{ +public: + /** + * Constructor. + * + * @param aConstrained is the point that is put under constrain. + * @parama aCenter is the point that is the center of the circle. + * @parama aEnd is the point that decides on the radius of the circle. + */ + EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) : + EDIT_CONSTRAINT( aConstrained ), m_center( aCenter ), m_end( aEnd ) + {} + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + ///> Point that imposes the constraint (center of the circle). + const EDIT_POINT& m_center; + + ///> Point that imposes the constraint (decides on the radius of the circle). + const EDIT_POINT& m_end; +}; + + +/** + * Class EC_CONVERGING + * + * EDIT_CONSTRAINT for 3 segment: dragged and two adjacent ones, enforcing to keep their slopes + * and allows only to change ending points. Applied to zones. + */ +class EC_CONVERGING : public EDIT_CONSTRAINT +{ +public: + EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ); + + virtual ~EC_CONVERGING(); + + ///> @copydoc EDIT_CONSTRAINT::Apply() + virtual void Apply( EDIT_POINT& aHandle ); + +private: + ///> Constraint for origin side segment. + EDIT_CONSTRAINT* m_originSideConstraint; + + ///> Constraint for end side segment. + EDIT_CONSTRAINT* m_endSideConstraint; + + ///> Additional constriant, applied when at least two points are collinear. It is a pointer to + ///> m_[origin/end]SideConstraint, so it should not be freed. + EDIT_CONSTRAINT* m_colinearConstraint; + + ///> Dragged segment. + EDIT_LINE& m_line; + + ///> EDIT_POINTS instance that stores currently modified lines. + EDIT_POINTS& m_editPoints; + + ///> Vector that represents the initial direction of the dragged segment. + VECTOR2I m_draggedVector; +}; + +#endif /* EDIT_CONSTRAINTS_H_ */ diff --git a/pcbnew/tools/edit_points.cpp b/pcbnew/tools/edit_points.cpp index 291caae818..9f6069d551 100644 --- a/pcbnew/tools/edit_points.cpp +++ b/pcbnew/tools/edit_points.cpp @@ -24,9 +24,8 @@ #include -#include "edit_points.h" #include -#include +#include "edit_points.h" bool EDIT_POINT::WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const { @@ -145,135 +144,3 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const aGal->PopDepth(); } - - -void EC_45DEGREE::Apply( EDIT_POINT& aHandle ) -{ - // Current line vector - VECTOR2I lineVector( aHandle.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 ); - - aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector ); -} - - -EC_LINE::EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : - EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) -{ - m_line = m_constrained.GetPosition() - m_constrainer.GetPosition(); -} - - -void EC_LINE::Apply( EDIT_POINT& aHandle ) -{ - SEG main( m_constrainer.GetPosition(), m_constrainer.GetPosition() + m_line ); - SEG projection( aHandle.GetPosition(), aHandle.GetPosition() + m_line.Perpendicular() ); - - if( OPT_VECTOR2I intersect = projection.IntersectLines( main ) ) - aHandle.SetPosition( *intersect ); -} - - -void EC_CIRCLE::Apply( EDIT_POINT& aHandle ) -{ - VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition(); - VECTOR2I centerToPoint = aHandle.GetPosition() - m_center.GetPosition(); - - int radius = centerToEnd.EuclideanNorm(); - double angle = centerToPoint.Angle(); - - VECTOR2I newLine( radius, 0 ); - newLine = newLine.Rotate( angle ); - - aHandle.SetPosition( m_center.GetPosition() + newLine ); -} - - -EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : - EDIT_CONSTRAINT( aLine.GetOrigin() ), - m_colinearConstraint( NULL ), m_line( aLine ), m_editPoints( aPoints ) -{ - // Dragged segment endings - EDIT_POINT& origin = aLine.GetOrigin(); - EDIT_POINT& end = aLine.GetEnd(); - - // Previous and next points, to make constraining lines (adjacent to the dragged line) - EDIT_POINT& prevOrigin = *aPoints.Previous( origin ); - EDIT_POINT& nextEnd = *aPoints.Next( end ); - - // Constraints for segments adjacent to the dragged one - m_originSideConstraint = new EC_LINE( origin, prevOrigin ); - m_endSideConstraint = new EC_LINE( end, nextEnd ); - - // Store the current vector of the line - m_draggedVector = end.GetPosition() - origin.GetPosition(); - - // Check for colinearity - SEG originSide( origin.GetPosition(), prevOrigin.GetPosition() ); - SEG endSide( end.GetPosition(), nextEnd.GetPosition() ); - SEG dragged( origin.GetPosition(), end.GetPosition() ); - - if( dragged.Collinear( originSide ) ) - m_colinearConstraint = m_originSideConstraint; - else if( dragged.Collinear( endSide ) ) - m_colinearConstraint = m_endSideConstraint; -} - - -EC_CONVERGING::~EC_CONVERGING() -{ - delete m_originSideConstraint; - delete m_endSideConstraint; - // m_colinearConstraint should not be freed, it is a pointer to one of the above -} - - -void EC_CONVERGING::Apply( EDIT_POINT& aHandle ) -{ - // The dragged segment endpoints - EDIT_POINT& origin = m_line.GetOrigin(); - EDIT_POINT& end = m_line.GetEnd(); - - if( m_colinearConstraint ) - { - m_colinearConstraint->Apply( origin ); - m_colinearConstraint->Apply( end ); - } - - // The dragged segment - SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector ); - - // Do not allow points on the adjacent segments move freely - m_originSideConstraint->Apply(); - m_endSideConstraint->Apply(); - - EDIT_POINT& prevOrigin = *m_editPoints.Previous( origin ); - EDIT_POINT& nextEnd = *m_editPoints.Next( end ); - - // Two segments adjacent to the dragged segment - SEG originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() ); - SEG endSide = SEG( end.GetPosition(), nextEnd.GetPosition() ); - - // First intersection point (dragged segment against origin side) - if( OPT_VECTOR2I originIntersect = dragged.IntersectLines( originSide ) ) - origin.SetPosition( *originIntersect ); - - // Second intersection point (dragged segment against end side) - if( OPT_VECTOR2I endIntersect = dragged.IntersectLines( endSide ) ) - end.SetPosition( *endIntersect ); - - // Check if adjacent segments intersect (did we dragged the line to the point that it may - // create a selfintersecting polygon?) - originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() ); - endSide = SEG( end.GetPosition(), nextEnd.GetPosition() ); - - if( OPT_VECTOR2I originEndIntersect = endSide.Intersect( originSide ) ) - { - origin.SetPosition( *originEndIntersect ); - end.SetPosition( *originEndIntersect ); - } -} diff --git a/pcbnew/tools/edit_points.h b/pcbnew/tools/edit_points.h index b2e99988e6..7177bd5241 100644 --- a/pcbnew/tools/edit_points.h +++ b/pcbnew/tools/edit_points.h @@ -25,57 +25,12 @@ #ifndef EDIT_POINTS_H_ #define EDIT_POINTS_H_ -#include -#include #include -#include - #include #include -class EDIT_POINT; - -/** - * Class EDIT_CONSTRAINT - * - * Allows to describe constraints between two edit handles. After the constrained handle is changed, - * Apply() has to be called to fix its coordinates according to the implemented constraint. - */ -template -class EDIT_CONSTRAINT -{ -public: - /** - * Constructor - * - * @param aConstrained is EDIT_POINT to which the constraint is applied. - */ - EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {}; - - virtual ~EDIT_CONSTRAINT() {}; - - /** - * Function Apply() - * - * Corrects coordinates of the constrained edit handle. - */ - virtual void Apply( EDIT_TYPE& aHandle ) = 0; - - /** - * Function Apply() - * - * Corrects coordinates of the constrained edit handle. - */ - void Apply() - { - Apply( m_constrained ); - } - -protected: - EDIT_TYPE& m_constrained; ///< Point that is constrained by rules implemented by Apply() -}; - +#include "edit_constraints.h" /** * Class EDIT_POINT @@ -458,182 +413,4 @@ private: std::deque m_lines; ///< EDIT_LINEs for modifying m_parent }; - -/** - * Class EC_VERTICAL. - * - * EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate. - */ -class EC_VERTICAL : public EDIT_CONSTRAINT -{ -public: - /** - * Constructor. - * - * @param aConstrained is the point that is put under constrain. - * @param aConstrainer is the point that is the source of the constrain. - */ - EC_VERTICAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : - EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) - {} - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ) - { - VECTOR2I point = aHandle.GetPosition(); - point.x = m_constrainer.GetPosition().x; - aHandle.SetPosition( point ); - } - -private: - const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. -}; - - -/** - * Class EC_HORIZONTAL. - * - * EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate. - */ -class EC_HORIZONTAL : public EDIT_CONSTRAINT -{ -public: - /** - * Constructor. - * - * @param aConstrained is the point that is put under constrain. - * @param aConstrainer is the point that is the source of the constrain. - */ - EC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : - EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) - {} - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ) - { - VECTOR2I point = aHandle.GetPosition(); - point.y = m_constrainer.GetPosition().y; - aHandle.SetPosition( point ); - } - -private: - const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. -}; - - -/** - * Class EC_45DEGREE - * - * EDIT_CONSTRAINT that imposes a constraint that two to be located at angle of 45 degree - * multiplicity. - */ -class EC_45DEGREE : public EDIT_CONSTRAINT -{ -public: - /** - * Constructor. - * - * @param aConstrained is the point that is put under constrain. - * @param aConstrainer is the point that is the source of the constrain. - */ - EC_45DEGREE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) : - EDIT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) - {} - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ); - -private: - const EDIT_POINT& m_constrainer; ///< Point that imposes the constraint. -}; - - -/** - * Class EC_LINE - * - * EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined - * by 2 points). - */ -class EC_LINE : public EDIT_CONSTRAINT -{ -public: - EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ); - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ); - -private: - EDIT_POINT m_constrainer; ///< Point that imposes the constraint. - VECTOR2I m_line; ///< Vector representing the constraining line. -}; - - -/** - * Class EC_CIRCLE. - * - * EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle. - */ -class EC_CIRCLE : public EDIT_CONSTRAINT -{ -public: - /** - * Constructor. - * - * @param aConstrained is the point that is put under constrain. - * @parama aCenter is the point that is the center of the circle. - * @parama aEnd is the point that decides on the radius of the circle. - */ - EC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) : - EDIT_CONSTRAINT( aConstrained ), m_center( aCenter ), m_end( aEnd ) - {} - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ); - -private: - ///> Point that imposes the constraint (center of the circle). - const EDIT_POINT& m_center; - - ///> Point that imposes the constraint (decides on the radius of the circle). - const EDIT_POINT& m_end; -}; - - -/** - * Class EC_CONVERGING - * - * EDIT_CONSTRAINT for 3 segment: dragged and two adjacent ones, enforcing to keep their slopes - * and allows only to change ending points. Applied to zones. - */ -class EC_CONVERGING : public EDIT_CONSTRAINT -{ -public: - EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ); - - virtual ~EC_CONVERGING(); - - ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ); - -private: - ///> Constraint for origin side segment. - EDIT_CONSTRAINT* m_originSideConstraint; - - ///> Constraint for end side segment. - EDIT_CONSTRAINT* m_endSideConstraint; - - ///> Additional constriant, applied when at least two points are collinear. It is a pointer to - ///> m_[origin/end]SideConstraint, so it should not be freed. - EDIT_CONSTRAINT* m_colinearConstraint; - - ///> Dragged segment. - EDIT_LINE& m_line; - - ///> EDIT_POINTS instance that stores currently modified lines. - EDIT_POINTS& m_editPoints; - - ///> Vector that represents the initial direction of the dragged segment. - VECTOR2I m_draggedVector; -}; - #endif /* EDIT_POINTS_H_ */