Implement Length and Width for RECT

This commit is contained in:
Josue 2023-06-25 04:55:50 -05:00 committed by Josue Huaroto
parent f31a524026
commit c3766bb250
3 changed files with 108 additions and 3 deletions

View File

@ -137,6 +137,26 @@ double EDA_SHAPE::GetLength() const
}
}
long long int EDA_SHAPE::GetRectangleLength() const
{
switch( m_shape )
{
case SHAPE_T::RECT: return GetEndX() - GetStartX();
default: UNIMPLEMENTED_FOR( SHAPE_T_asString() );
}
}
long long int EDA_SHAPE::GetRectangleWidth() const
{
switch( m_shape )
{
case SHAPE_T::RECT: return GetEndY() - GetStartY();
default: UNIMPLEMENTED_FOR( SHAPE_T_asString() );
}
}
void EDA_SHAPE::SetLength( const double& aLength )
{
switch( m_shape )
@ -147,6 +167,20 @@ void EDA_SHAPE::SetLength( const double& aLength )
}
}
void EDA_SHAPE::SetRectangle(const long long int& aLength, const long long int& aWidth)
{
switch ( m_shape )
{
case SHAPE_T::RECT:
m_rectangleLength = aLength;
m_rectangleWidth = aWidth;
break;
default: UNIMPLEMENTED_FOR( SHAPE_T_asString() );
}
}
void EDA_SHAPE::SetAngle( const EDA_ANGLE& aAngle )
{
switch( m_shape )

View File

@ -301,6 +301,8 @@ public:
void SetLength( const double& aLength );
void SetRectangle( const long long int& aLength, const long long int& aWidth );
void SetAngle( const EDA_ANGLE& aLength );
/**
@ -310,6 +312,9 @@ public:
*/
double GetLength() const;
long long int GetRectangleLength() const;
long long int GetRectangleWidth() const;
/**
* Convert the shape to a closed polygon. Circles and arcs are approximated by segments.
*
@ -372,6 +377,9 @@ protected:
FILL_T m_fill;
COLOR4D m_fillColor;
long long int m_rectangleLength;
long long int m_rectangleWidth;
double m_segmentLength;
EDA_ANGLE m_segmentAngle;

View File

@ -85,6 +85,8 @@ private:
UNIT_BINDER m_thickness;
UNIT_BINDER m_segmentLength;
UNIT_BINDER m_segmentAngle;
UNIT_BINDER m_rectangleLength;
UNIT_BINDER m_rectangleWidth;
UNIT_BINDER m_bezierCtrl1X, m_bezierCtrl1Y;
UNIT_BINDER m_bezierCtrl2X, m_bezierCtrl2Y;
@ -102,6 +104,8 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR
m_endY( aParent, m_endYLabel, m_endYCtrl, m_endYUnits ),
m_segmentLength( aParent, m_segmentLengthLabel, m_segmentLengthCtrl, m_segmentLengthUnits ),
m_segmentAngle( aParent, m_segmentAngleLabel, m_segmentAngleCtrl, m_segmentAngleUnits ),
m_rectangleLength( aParent, m_rectangleLengthLabel, m_rectangleLengthCtrl, m_rectangleLengthUnits ),
m_rectangleWidth( aParent, m_rectangleWidthLabel, m_rectangleWidthCtrl, m_rectangleWidthUnits ),
m_angle( aParent, m_angleLabel, m_angleCtrl, m_angleUnits ),
m_thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits ),
m_bezierCtrl1X( aParent, m_BezierPointC1XLabel, m_BezierC1X_Ctrl, m_BezierPointC1XUnit ),
@ -122,6 +126,10 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR
m_segmentLength.SetUnits( EDA_UNITS::MILLIMETRES );
m_segmentAngle.SetUnits( EDA_UNITS::DEGREES );
m_rectangleLength.SetUnits( EDA_UNITS::MILLIMETRES );
m_rectangleWidth.SetUnits( EDA_UNITS::MILLIMETRES );
m_angle.SetUnits( EDA_UNITS::DEGREES );
// Do not allow locking items in the footprint editor
@ -234,6 +242,12 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
m_segmentAngle.Show( false );
}
if( m_item->GetShape() != SHAPE_T::RECT )
{
m_rectangleLength.Show( false );
m_rectangleWidth.Show( false );
}
// Only an arc has a angle parameter. So do not show this parameter for other shapes
if( m_item->GetShape() != SHAPE_T::ARC )
m_angle.Show( false );
@ -283,6 +297,9 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
case SHAPE_T::RECTANGLE:
SetTitle( _( "Rectangle Properties" ) );
m_rectangleLength.SetValue( m_item->GetRectangleLength() );
m_rectangleWidth.SetValue( m_item->GetRectangleWidth() );
m_filledCtrl->Show( true );
break;
@ -373,13 +390,27 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow()
VECTOR2I begin_point = m_item->GetStart();
VECTOR2I end_point = m_item->GetEnd();
long long int segment_length = m_item->GetLength();
EDA_ANGLE segment_angle = m_item->GetSegmentAngle();
long long int segment_length = 0;
EDA_ANGLE segment_angle = EDA_ANGLE( 0, RADIANS_T );
long long int rectangle_length = 0;
long long int rectangle_width = 0;
BOARD_COMMIT commit( m_parent );
commit.Modify( m_item );
if( m_item->GetShape() == SHAPE_T::SEGMENT )
{
segment_length = m_item->GetLength();
segment_angle = m_item->GetSegmentAngle();
}
if( m_item->GetShape() == SHAPE_T::RECT )
{
rectangle_length = m_item->GetRectangleLength();
rectangle_width = m_item->GetRectangleWidth();
}
if( m_flipStartEnd && m_item->GetShape() != SHAPE_T::ARC )
{
m_item->SetEndX( m_startX.GetValue() );
@ -455,7 +486,39 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow()
}
// For Bezier curve: Set the two control points
if( m_item->GetShape() == SHAPE_T::RECT )
{
bool change_begin = ( begin_point != m_item->GetStart() );
bool change_end = ( end_point != m_item->GetEnd() );
bool change_length = ( rectangle_length != m_rectangleLength.GetValue() );
bool change_width = ( rectangle_width != m_rectangleWidth.GetValue() );
if( !( change_begin && change_end ) )
{
rectangle_length = m_rectangleLength.GetValue();
rectangle_width = m_rectangleWidth.GetValue();
if( change_length || change_width )
{
if( change_end )
{
m_item->SetStartX( m_item->GetEndX() - rectangle_length );
m_item->SetStartY( m_item->GetEndY() - rectangle_width );
}
else
{
m_item->SetEndX( m_item->GetStartX() + rectangle_length );
m_item->SetEndY( m_item->GetStartY() + rectangle_width );
}
}
}
m_item->SetRectangle( m_rectangleLength.GetValue(), m_rectangleWidth.GetValue() );
}
// For Bezier curve: Set the two control points
if( m_item->GetShape() == SHAPE_T::BEZIER )
{
m_item->SetBezierC1( VECTOR2I( m_bezierCtrl1X.GetValue(), m_bezierCtrl1Y.GetValue() ) );