From 1828edbabe57868e6b0eb7e5fba2fbd8f366077d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 2 Apr 2014 09:31:35 +0200 Subject: [PATCH] Refactoring EDIT_POINTS, part 3: constraints split to EDIT_POINTs and EDIT_LINEs. --- pcbnew/tools/edit_constraints.cpp | 10 +++++----- pcbnew/tools/edit_constraints.h | 13 +++++-------- pcbnew/tools/edit_points.h | 28 +++++++++++++++++++++++++++- pcbnew/tools/point_editor.cpp | 5 ++--- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/pcbnew/tools/edit_constraints.cpp b/pcbnew/tools/edit_constraints.cpp index 91e14ea82d..84d417c2ab 100644 --- a/pcbnew/tools/edit_constraints.cpp +++ b/pcbnew/tools/edit_constraints.cpp @@ -90,8 +90,8 @@ void EC_CIRCLE::Apply( EDIT_POINT& aHandle ) EC_CONVERGING::EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ) : - EDIT_CONSTRAINT( aLine.GetOrigin() ), - m_colinearConstraint( NULL ), m_line( aLine ), m_editPoints( aPoints ) + EDIT_CONSTRAINT( aLine ), + m_colinearConstraint( NULL ), m_editPoints( aPoints ) { // Dragged segment endings EDIT_POINT& origin = aLine.GetOrigin(); @@ -128,11 +128,11 @@ EC_CONVERGING::~EC_CONVERGING() } -void EC_CONVERGING::Apply( EDIT_POINT& aHandle ) +void EC_CONVERGING::Apply( EDIT_LINE& aHandle ) { // The dragged segment endpoints - EDIT_POINT& origin = m_line.GetOrigin(); - EDIT_POINT& end = m_line.GetEnd(); + EDIT_POINT& origin = m_constrained.GetOrigin(); + EDIT_POINT& end = m_constrained.GetEnd(); if( m_colinearConstraint ) { diff --git a/pcbnew/tools/edit_constraints.h b/pcbnew/tools/edit_constraints.h index b26c4f69f7..c86afb5a75 100644 --- a/pcbnew/tools/edit_constraints.h +++ b/pcbnew/tools/edit_constraints.h @@ -127,8 +127,8 @@ private: /** * Class EC_45DEGREE * - * EDIT_CONSTRAINT that imposes a constraint that two to be located at angle of 45 degree - * multiplicity. + * EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45 + * degree multiplicity. */ class EC_45DEGREE : public EDIT_CONSTRAINT { @@ -205,10 +205,10 @@ private: /** * Class EC_CONVERGING * - * EDIT_CONSTRAINT for 3 segment: dragged and two adjacent ones, enforcing to keep their slopes + * EDIT_CONSTRAINT for 3 segments: 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 +class EC_CONVERGING : public EDIT_CONSTRAINT { public: EC_CONVERGING( EDIT_LINE& aLine, EDIT_POINTS& aPoints ); @@ -216,7 +216,7 @@ public: virtual ~EC_CONVERGING(); ///> @copydoc EDIT_CONSTRAINT::Apply() - virtual void Apply( EDIT_POINT& aHandle ); + virtual void Apply( EDIT_LINE& aHandle ); private: ///> Constraint for origin side segment. @@ -229,9 +229,6 @@ private: ///> 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; diff --git a/pcbnew/tools/edit_points.h b/pcbnew/tools/edit_points.h index 2e5bddff62..52f54960ff 100644 --- a/pcbnew/tools/edit_points.h +++ b/pcbnew/tools/edit_points.h @@ -165,7 +165,7 @@ public: ///> Single point size in pixels static const int POINT_SIZE = 10; -protected: +private: ///> Position of EDIT_POINT VECTOR2I m_position; @@ -221,6 +221,29 @@ public: m_constraint->Apply(); } + /** + * Function SetConstraint() + * + * Sets a constraint for and EDIT_POINT. + * @param aConstraint is the constraint to be set. + */ + void SetConstraint( EDIT_CONSTRAINT* aConstraint ) + { + m_constraint.reset( aConstraint ); + } + + /** + * Function GetConstraint() + * + * Returns the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is + * returned. + */ + EDIT_CONSTRAINT* GetConstraint() const + { + return m_constraint.get(); + } + + /** * Function GetOrigin() * @@ -264,6 +287,9 @@ public: private: EDIT_POINT& m_origin; ///< Origin point for a line EDIT_POINT& m_end; ///< End point for a line + + ///> Constraint for the point, NULL if none + boost::shared_ptr > m_constraint; }; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 167b8247bf..5fd82edf53 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -575,12 +575,11 @@ void POINT_EDITOR::setAltConstraint( bool aEnabled ) if( aEnabled ) { EDIT_LINE* line = dynamic_cast( m_dragPoint ); + if( line ) { if( m_editPoints->GetParent()->Type() == PCB_ZONE_AREA_T ) - { - m_altConstraint.reset( new EC_CONVERGING( *line, *m_editPoints ) ); - } + m_altConstraint.reset( (EDIT_CONSTRAINT*)( new EC_CONVERGING( *line, *m_editPoints ) ) ); } else {