Commit 6b90eb3a authored by Maciej Suminski's avatar Maciej Suminski

Refactoring EDIT_POINTS, part 1: separated functions that operate on EDIT_POINTS and EDIT_LINES.

parent e79934b0
...@@ -83,9 +83,15 @@ EDIT_POINT* EDIT_POINTS::Previous( const EDIT_POINT& aPoint ) ...@@ -83,9 +83,15 @@ EDIT_POINT* EDIT_POINTS::Previous( const EDIT_POINT& aPoint )
} }
} }
return NULL;
}
EDIT_LINE* EDIT_POINTS::Previous( const EDIT_LINE& aLine )
{
for( unsigned int i = 0; i < m_lines.size(); ++i ) for( unsigned int i = 0; i < m_lines.size(); ++i )
{ {
if( m_lines[i] == aPoint ) if( m_lines[i] == aLine )
{ {
if( i == 0 ) if( i == 0 )
return &m_lines[m_lines.size() - 1]; return &m_lines[m_lines.size() - 1];
...@@ -111,9 +117,15 @@ EDIT_POINT* EDIT_POINTS::Next( const EDIT_POINT& aPoint ) ...@@ -111,9 +117,15 @@ EDIT_POINT* EDIT_POINTS::Next( const EDIT_POINT& aPoint )
} }
} }
return NULL;
}
EDIT_LINE* EDIT_POINTS::Next( const EDIT_LINE& aLine )
{
for( unsigned int i = 0; i < m_lines.size(); ++i ) for( unsigned int i = 0; i < m_lines.size(); ++i )
{ {
if( m_lines[i] == aPoint ) if( m_lines[i] == aLine )
{ {
if( i == m_lines.size() - 1 ) if( i == m_lines.size() - 1 )
return &m_lines[0]; return &m_lines[0];
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
} }
/** /**
* Function GetX() * Function GetY()
* *
* Returns Y coordinate of an EDIT_POINT. * Returns Y coordinate of an EDIT_POINT.
*/ */
...@@ -356,6 +356,8 @@ public: ...@@ -356,6 +356,8 @@ public:
*/ */
EDIT_POINT* Previous( const EDIT_POINT& aPoint ); EDIT_POINT* Previous( const EDIT_POINT& aPoint );
EDIT_LINE* Previous( const EDIT_LINE& aLine );
/** /**
* Function Next() * Function Next()
* *
...@@ -367,16 +369,28 @@ public: ...@@ -367,16 +369,28 @@ public:
*/ */
EDIT_POINT* Next( const EDIT_POINT& aPoint ); EDIT_POINT* Next( const EDIT_POINT& aPoint );
EDIT_POINT& operator[]( unsigned int aIndex ) EDIT_LINE* Next( const EDIT_LINE& aLine );
EDIT_POINT& Point( unsigned int aIndex )
{ {
return m_points[aIndex]; return m_points[aIndex];
} }
const EDIT_POINT& operator[]( unsigned int aIndex ) const const EDIT_POINT& Point( unsigned int aIndex ) const
{ {
return m_points[aIndex]; return m_points[aIndex];
} }
EDIT_LINE& Line( unsigned int aIndex )
{
return m_lines[aIndex];
}
const EDIT_LINE& Line( unsigned int aIndex ) const
{
return m_lines[aIndex];
}
/** /**
* Function Size() * Function Size()
* *
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
switch( segment->GetShape() ) switch( segment->GetShape() )
{ {
case S_SEGMENT: case S_SEGMENT:
points->AddPoint( segment->GetStart() ); // points[0] points->AddPoint( segment->GetStart() ); // points[0] // TODO add enums for points
points->AddPoint( segment->GetEnd() ); // points[1] points->AddPoint( segment->GetEnd() ); // points[1]
break; break;
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
// Set constraints // Set constraints
// Arc end has to stay at the same radius as the start // Arc end has to stay at the same radius as the start
(*points)[2].SetConstraint( new EC_CIRCLE( (*points)[2], (*points)[0], (*points)[1] ) ); points->Point( 2 ).SetConstraint( new EC_CIRCLE( points->Point( 2 ), points->Point( 0 ), points->Point( 1 ) ) );
break; break;
case S_CIRCLE: case S_CIRCLE:
...@@ -99,10 +99,10 @@ public: ...@@ -99,10 +99,10 @@ public:
// Lines have to be added after creating edit points, so they use EDIT_POINT references // Lines have to be added after creating edit points, so they use EDIT_POINT references
for( int i = 0; i < cornersCount - 1; ++i ) for( int i = 0; i < cornersCount - 1; ++i )
points->AddLine( (*points)[i], (*points)[i + 1] ); points->AddLine( points->Point( i ), points->Point( i + 1 ) );
// The last missing line, connecting the last and the first polygon point // The last missing line, connecting the last and the first polygon point
points->AddLine( (*points)[cornersCount - 1], (*points)[0] ); points->AddLine( points->Point( cornersCount - 1 ), points->Point( 0 ) );
break; break;
} }
...@@ -116,8 +116,8 @@ public: ...@@ -116,8 +116,8 @@ public:
points->AddPoint( dimension->m_featureLineDO ); points->AddPoint( dimension->m_featureLineDO );
// Dimension height setting - edit points should move only along the feature lines // Dimension height setting - edit points should move only along the feature lines
(*points)[0].SetConstraint( new EC_LINE( (*points)[0], (*points)[2] ) ); points->Point( 0 ).SetConstraint( new EC_LINE( points->Point( 0 ), points->Point( 2 ) ) );
(*points)[1].SetConstraint( new EC_LINE( (*points)[1], (*points)[3] ) ); points->Point( 1 ).SetConstraint( new EC_LINE( points->Point( 1 ), points->Point( 3 ) ) );
break; break;
} }
...@@ -322,29 +322,29 @@ void POINT_EDITOR::updateItem() const ...@@ -322,29 +322,29 @@ void POINT_EDITOR::updateItem() const
switch( segment->GetShape() ) switch( segment->GetShape() )
{ {
case S_SEGMENT: case S_SEGMENT:
if( isModified( (*m_editPoints)[0] ) ) if( isModified( m_editPoints->Point( 0 ) ) )
segment->SetStart( wxPoint( (*m_editPoints)[0].GetPosition().x, segment->SetStart( wxPoint( m_editPoints->Point( 0 ).GetPosition().x,
(*m_editPoints)[0].GetPosition().y ) ); m_editPoints->Point( 0 ).GetPosition().y ) );
else if( isModified( (*m_editPoints)[1] ) ) else if( isModified( m_editPoints->Point( 1 ) ) )
segment->SetEnd( wxPoint( (*m_editPoints)[1].GetPosition().x, segment->SetEnd( wxPoint( m_editPoints->Point( 1 ).GetPosition().x,
(*m_editPoints)[1].GetPosition().y ) ); m_editPoints->Point( 1 ).GetPosition().y ) );
break; break;
case S_ARC: case S_ARC:
{ {
const VECTOR2I& center = (*m_editPoints)[0].GetPosition(); const VECTOR2I& center = m_editPoints->Point( 0 ).GetPosition();
const VECTOR2I& start = (*m_editPoints)[1].GetPosition(); const VECTOR2I& start = m_editPoints->Point( 1 ).GetPosition();
const VECTOR2I& end = (*m_editPoints)[2].GetPosition(); const VECTOR2I& end = m_editPoints->Point( 2 ).GetPosition();
if( center != segment->GetCenter() ) if( center != segment->GetCenter() )
{ {
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
segment->Move( moveVector ); segment->Move( moveVector );
(*m_editPoints)[1].SetPosition( segment->GetArcStart() ); m_editPoints->Point( 1 ).SetPosition( segment->GetArcStart() );
(*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); m_editPoints->Point( 2 ).SetPosition( segment->GetArcEnd() );
} }
else else
...@@ -371,10 +371,10 @@ void POINT_EDITOR::updateItem() const ...@@ -371,10 +371,10 @@ void POINT_EDITOR::updateItem() const
case S_CIRCLE: case S_CIRCLE:
{ {
const VECTOR2I& center = (*m_editPoints)[0].GetPosition(); const VECTOR2I& center = m_editPoints->Point( 0 ).GetPosition();
const VECTOR2I& end = (*m_editPoints)[1].GetPosition(); const VECTOR2I& end = m_editPoints->Point( 1 ).GetPosition();
if( isModified( (*m_editPoints)[0] ) ) if( isModified( m_editPoints->Point( 0 ) ) )
{ {
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
segment->Move( moveVector ); segment->Move( moveVector );
...@@ -402,8 +402,8 @@ void POINT_EDITOR::updateItem() const ...@@ -402,8 +402,8 @@ void POINT_EDITOR::updateItem() const
for( int i = 0; i < outline->GetCornersCount(); ++i ) for( int i = 0; i < outline->GetCornersCount(); ++i )
{ {
outline->SetX( i, (*m_editPoints)[i].GetPosition().x ); outline->SetX( i, m_editPoints->Point( i ).GetPosition().x );
outline->SetY( i, (*m_editPoints)[i].GetPosition().y ); outline->SetY( i, m_editPoints->Point( i ).GetPosition().y );
} }
break; break;
...@@ -414,7 +414,7 @@ void POINT_EDITOR::updateItem() const ...@@ -414,7 +414,7 @@ void POINT_EDITOR::updateItem() const
DIMENSION* dimension = static_cast<DIMENSION*>( item ); DIMENSION* dimension = static_cast<DIMENSION*>( item );
// Check which point is currently modified and updated dimension's points respectively // Check which point is currently modified and updated dimension's points respectively
if( isModified( (*m_editPoints)[0] ) ) if( isModified( m_editPoints->Point( 0 ) ) )
{ {
VECTOR2D featureLine( m_dragPoint->GetPosition() - dimension->GetOrigin() ); VECTOR2D featureLine( m_dragPoint->GetPosition() - dimension->GetOrigin() );
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() ); VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
...@@ -425,7 +425,7 @@ void POINT_EDITOR::updateItem() const ...@@ -425,7 +425,7 @@ void POINT_EDITOR::updateItem() const
dimension->SetHeight( featureLine.EuclideanNorm() ); dimension->SetHeight( featureLine.EuclideanNorm() );
} }
else if( isModified( (*m_editPoints)[1] ) ) else if( isModified( m_editPoints->Point( 1 ) ) )
{ {
VECTOR2D featureLine( m_dragPoint->GetPosition() - dimension->GetEnd() ); VECTOR2D featureLine( m_dragPoint->GetPosition() - dimension->GetEnd() );
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() ); VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
...@@ -436,18 +436,18 @@ void POINT_EDITOR::updateItem() const ...@@ -436,18 +436,18 @@ void POINT_EDITOR::updateItem() const
dimension->SetHeight( featureLine.EuclideanNorm() ); dimension->SetHeight( featureLine.EuclideanNorm() );
} }
else if( isModified( (*m_editPoints)[2] ) ) else if( isModified( m_editPoints->Point( 2 ) ) )
{ {
dimension->SetOrigin( wxPoint( m_dragPoint->GetPosition().x, m_dragPoint->GetPosition().y ) ); dimension->SetOrigin( wxPoint( m_dragPoint->GetPosition().x, m_dragPoint->GetPosition().y ) );
(*m_editPoints)[0].SetConstraint( new EC_LINE( (*m_editPoints)[0], (*m_editPoints)[2] ) ); m_editPoints->Point( 0 ).SetConstraint( new EC_LINE( m_editPoints->Point( 0 ), m_editPoints->Point( 2 ) ) );
(*m_editPoints)[1].SetConstraint( new EC_LINE( (*m_editPoints)[1], (*m_editPoints)[3] ) ); m_editPoints->Point( 1 ).SetConstraint( new EC_LINE( m_editPoints->Point( 1 ), m_editPoints->Point( 3 ) ) );
} }
else if( isModified( (*m_editPoints)[3] ) ) else if( isModified( m_editPoints->Point( 3 ) ) )
{ {
dimension->SetEnd( wxPoint( m_dragPoint->GetPosition().x, m_dragPoint->GetPosition().y ) ); dimension->SetEnd( wxPoint( m_dragPoint->GetPosition().x, m_dragPoint->GetPosition().y ) );
(*m_editPoints)[0].SetConstraint( new EC_LINE( (*m_editPoints)[0], (*m_editPoints)[2] ) ); m_editPoints->Point( 0 ).SetConstraint( new EC_LINE( m_editPoints->Point( 0 ), m_editPoints->Point( 2 ) ) );
(*m_editPoints)[1].SetConstraint( new EC_LINE( (*m_editPoints)[1], (*m_editPoints)[3] ) ); m_editPoints->Point( 1 ).SetConstraint( new EC_LINE( m_editPoints->Point( 1 ), m_editPoints->Point( 3 ) ) );
} }
break; break;
...@@ -486,19 +486,19 @@ void POINT_EDITOR::updatePoints() const ...@@ -486,19 +486,19 @@ void POINT_EDITOR::updatePoints() const
switch( segment->GetShape() ) switch( segment->GetShape() )
{ {
case S_SEGMENT: case S_SEGMENT:
(*m_editPoints)[0].SetPosition( segment->GetStart() ); m_editPoints->Point( 0 ).SetPosition( segment->GetStart() );
(*m_editPoints)[1].SetPosition( segment->GetEnd() ); m_editPoints->Point( 1 ).SetPosition( segment->GetEnd() );
break; break;
case S_ARC: case S_ARC:
(*m_editPoints)[0].SetPosition( segment->GetCenter() ); m_editPoints->Point( 0 ).SetPosition( segment->GetCenter() );
(*m_editPoints)[1].SetPosition( segment->GetArcStart() ); m_editPoints->Point( 1 ).SetPosition( segment->GetArcStart() );
(*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); m_editPoints->Point( 2 ).SetPosition( segment->GetArcEnd() );
break; break;
case S_CIRCLE: case S_CIRCLE:
(*m_editPoints)[0].SetPosition( segment->GetCenter() ); m_editPoints->Point( 0 ).SetPosition( segment->GetCenter() );
(*m_editPoints)[1].SetPosition( segment->GetEnd() ); m_editPoints->Point( 1 ).SetPosition( segment->GetEnd() );
break; break;
default: // suppress warnings default: // suppress warnings
...@@ -515,7 +515,7 @@ void POINT_EDITOR::updatePoints() const ...@@ -515,7 +515,7 @@ void POINT_EDITOR::updatePoints() const
const CPolyLine* outline = zone->Outline(); const CPolyLine* outline = zone->Outline();
for( int i = 0; i < outline->GetCornersCount(); ++i ) for( int i = 0; i < outline->GetCornersCount(); ++i )
(*m_editPoints)[i].SetPosition( outline->GetPos( i ) ); m_editPoints->Point( i ).SetPosition( outline->GetPos( i ) );
break; break;
} }
...@@ -524,10 +524,10 @@ void POINT_EDITOR::updatePoints() const ...@@ -524,10 +524,10 @@ void POINT_EDITOR::updatePoints() const
{ {
const DIMENSION* dimension = static_cast<const DIMENSION*>( item ); const DIMENSION* dimension = static_cast<const DIMENSION*>( item );
(*m_editPoints)[0].SetPosition( dimension->m_crossBarO ); m_editPoints->Point( 0 ).SetPosition( dimension->m_crossBarO );
(*m_editPoints)[1].SetPosition( dimension->m_crossBarF ); m_editPoints->Point( 1 ).SetPosition( dimension->m_crossBarF );
(*m_editPoints)[2].SetPosition( dimension->m_featureLineGO ); m_editPoints->Point( 2 ).SetPosition( dimension->m_featureLineGO );
(*m_editPoints)[3].SetPosition( dimension->m_featureLineDO ); m_editPoints->Point( 3 ).SetPosition( dimension->m_featureLineDO );
break; break;
} }
...@@ -580,7 +580,7 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const ...@@ -580,7 +580,7 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const
case S_ARC: case S_ARC:
case S_CIRCLE: case S_CIRCLE:
return (*m_editPoints)[0]; // center return m_editPoints->Point( 0 ); // center
default: // suppress warnings default: // suppress warnings
break; break;
...@@ -593,11 +593,11 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const ...@@ -593,11 +593,11 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const
case PCB_DIMENSION_T: case PCB_DIMENSION_T:
{ {
// Constraint for crossbar // Constraint for crossbar
if( isModified( (*m_editPoints)[2] ) ) if( isModified( m_editPoints->Point( 2 ) ) )
return (*m_editPoints)[3]; return m_editPoints->Point( 3 );
else if( isModified( (*m_editPoints)[3] ) ) else if( isModified( m_editPoints->Point( 3 ) ) )
return (*m_editPoints)[2]; return m_editPoints->Point( 2 );
else else
return EDIT_POINT( m_dragPoint->GetPosition() ); // no constraint return EDIT_POINT( m_dragPoint->GetPosition() ); // no constraint
......
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