Support Bezier curve editing in eeschema.

This commit is contained in:
Alex Shvartzkop 2024-01-16 14:11:25 +03:00
parent 338914c7cf
commit 5bd620d8f9
3 changed files with 84 additions and 6 deletions

View File

@ -1353,6 +1353,16 @@ void EDA_SHAPE::beginEdit( const VECTOR2I& aPosition )
m_editState = 1;
break;
case SHAPE_T::BEZIER:
SetStart( aPosition );
SetEnd( aPosition );
SetBezierC1( aPosition );
SetBezierC2( aPosition );
m_editState = 1;
RebuildBezierToSegmentsPointsList( GetWidth() );
break;
case SHAPE_T::POLY:
m_poly.NewOutline();
m_poly.Outline( 0 ).SetClosed( false );
@ -1378,6 +1388,13 @@ bool EDA_SHAPE::continueEdit( const VECTOR2I& aPosition )
case SHAPE_T::RECTANGLE:
return false;
case SHAPE_T::BEZIER:
if( m_editState == 3 )
return false;
m_editState++;
return true;
case SHAPE_T::POLY:
{
SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 );
@ -1407,6 +1424,28 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition )
SetEnd( aPosition );
break;
case SHAPE_T::BEZIER:
{
switch( m_editState )
{
case 0:
SetStart( aPosition );
SetEnd( aPosition );
SetBezierC1( aPosition );
SetBezierC2( aPosition );
break;
case 1:
SetBezierC2( aPosition );
SetEnd( aPosition );
break;
case 2: SetBezierC1( aPosition ); break;
case 3: SetBezierC2( aPosition ); break;
}
RebuildBezierToSegmentsPointsList( GetWidth() );
}
break;
case SHAPE_T::ARC:
{
double radius = GetRadius();
@ -1528,6 +1567,7 @@ void EDA_SHAPE::endEdit( bool aClosed )
case SHAPE_T::SEGMENT:
case SHAPE_T::CIRCLE:
case SHAPE_T::RECTANGLE:
case SHAPE_T::BEZIER:
break;
case SHAPE_T::POLY:

View File

@ -1465,6 +1465,9 @@ void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aContro
BEZIER_POLY converter( pointCtrl );
converter.GetPoly( output, aFilterValue );
if( output.size() == 1 )
output.push_back( output.front() );
DrawPolygon( &output[0], output.size() );
}

View File

@ -52,16 +52,19 @@ enum ARC_POINTS
ARC_CENTER, ARC_START, ARC_END
};
enum CIRCLE_POINTS
{
CIRC_CENTER, CIRC_END
};
enum RECTANGLE_POINTS
{
RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT
};
enum RECTANGLE_LINES
{
RECT_TOP, RECT_RIGHT, RECT_BOT, RECT_LEFT
@ -73,6 +76,16 @@ enum LINE_POINTS
LINE_START, LINE_END
};
enum BEZIER_CURVE_POINTS
{
BEZIER_CURVE_START,
BEZIER_CURVE_CONTROL_POINT1,
BEZIER_CURVE_CONTROL_POINT2,
BEZIER_CURVE_END
};
class EDIT_POINTS_FACTORY
{
public:
@ -134,7 +147,10 @@ public:
break;
case SHAPE_T::BEZIER:
// TODO
points->AddPoint( mapCoords( shape->GetStart() ) );
points->AddPoint( mapCoords( shape->GetBezierC1() ) );
points->AddPoint( mapCoords( shape->GetBezierC2() ) );
points->AddPoint( mapCoords( shape->GetEnd() ) );
break;
default:
@ -218,7 +234,10 @@ public:
break;
case SHAPE_T::BEZIER:
// TODO
points->AddPoint( shape->GetStart() );
points->AddPoint( shape->GetBezierC1() );
points->AddPoint( shape->GetBezierC2() );
points->AddPoint( shape->GetEnd() );
break;
default:
@ -771,7 +790,12 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
}
case SHAPE_T::BEZIER:
// TODO
shape->SetStart( mapCoords( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition() ) );
shape->SetBezierC1( mapCoords( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition() ) );
shape->SetBezierC2( mapCoords( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition() ) );
shape->SetEnd( mapCoords( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition() ) );
shape->RebuildBezierToSegmentsPointsList( shape->GetWidth() );
break;
default:
@ -925,7 +949,12 @@ void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
}
case SHAPE_T::BEZIER:
// TODO
shape->SetStart( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition() );
shape->SetBezierC1( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition() );
shape->SetBezierC2( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition() );
shape->SetEnd( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition() );
shape->RebuildBezierToSegmentsPointsList( shape->GetWidth() );
break;
default:
@ -1196,7 +1225,10 @@ void EE_POINT_EDITOR::updatePoints()
}
case SHAPE_T::BEZIER:
// TODO
m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( mapCoords( shape->GetStart() ) );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( mapCoords( shape->GetBezierC1() ) );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( mapCoords( shape->GetBezierC2() ) );
m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( mapCoords( shape->GetEnd() ) );
break;
default:
@ -1284,7 +1316,10 @@ void EE_POINT_EDITOR::updatePoints()
}
case SHAPE_T::BEZIER:
// TODO
m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( shape->GetStart() );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( shape->GetBezierC1() );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( shape->GetBezierC2() );
m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( shape->GetEnd() );
break;
default: