mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Point editor: unify segment, circle, bezier and tablecells (partial)
For segment, circle, beziers, these are the same in all editors and only need access to the EDA_SHAPE nature, so we can remove the duplication entirely. For TABLECELLs, while the cells are polymorphic in that PCB and SCH cells are both EDA_SHAPEs (via the TEXTBOXes), the parent TABLES are not polymorphic, and thus the implementation can't be trivially de-duplicated. Rather than do something with templates, just keep it simple for now and maybe look at unifying tables later on.
This commit is contained in:
parent
e6e1253fea
commit
87cd0a74f2
@ -99,3 +99,147 @@ void POLYGON_POINT_EDIT_BEHAVIOR::UpdateOutlineFromPoints( SHAPE_POLY_SET& aOu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EDA_SEGMENT_POINT_EDIT_BEHAVIOR::MakePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
aPoints.AddPoint( m_segment.GetStart() );
|
||||
aPoints.AddPoint( m_segment.GetEnd() );
|
||||
}
|
||||
|
||||
void EDA_SEGMENT_POINT_EDIT_BEHAVIOR::UpdatePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, SEGMENT_MAX_POINTS );
|
||||
|
||||
aPoints.Point( SEGMENT_START ) = m_segment.GetStart();
|
||||
aPoints.Point( SEGMENT_END ) = m_segment.GetEnd();
|
||||
}
|
||||
|
||||
void EDA_SEGMENT_POINT_EDIT_BEHAVIOR::UpdateItem( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, SEGMENT_MAX_POINTS );
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( SEGMENT_START ) ) )
|
||||
m_segment.SetStart( aPoints.Point( SEGMENT_START ).GetPosition() );
|
||||
|
||||
else if( isModified( aEditedPoint, aPoints.Point( SEGMENT_END ) ) )
|
||||
m_segment.SetEnd( aPoints.Point( SEGMENT_END ).GetPosition() );
|
||||
}
|
||||
|
||||
OPT_VECTOR2I
|
||||
EDA_SEGMENT_POINT_EDIT_BEHAVIOR::Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const
|
||||
{
|
||||
// Select the other end of line
|
||||
return aPoints.Next( aEditedPoint )->GetPosition();
|
||||
}
|
||||
|
||||
|
||||
void EDA_CIRCLE_POINT_EDIT_BEHAVIOR::MakePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
aPoints.AddPoint( m_circle.getCenter() );
|
||||
aPoints.AddPoint( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
|
||||
void EDA_CIRCLE_POINT_EDIT_BEHAVIOR::UpdatePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, CIRC_MAX_POINTS );
|
||||
|
||||
aPoints.Point( CIRC_CENTER ).SetPosition( m_circle.getCenter() );
|
||||
aPoints.Point( CIRC_END ).SetPosition( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
|
||||
void EDA_CIRCLE_POINT_EDIT_BEHAVIOR::UpdateItem( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, CIRC_MAX_POINTS );
|
||||
|
||||
const VECTOR2I& center = aPoints.Point( CIRC_CENTER ).GetPosition();
|
||||
const VECTOR2I& end = aPoints.Point( CIRC_END ).GetPosition();
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( CIRC_CENTER ) ) )
|
||||
{
|
||||
m_circle.SetCenter( center );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_circle.SetEnd( VECTOR2I( end.x, end.y ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OPT_VECTOR2I
|
||||
EDA_CIRCLE_POINT_EDIT_BEHAVIOR::Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const
|
||||
{
|
||||
return aPoints.Point( CIRC_CENTER ).GetPosition();
|
||||
}
|
||||
|
||||
|
||||
void EDA_BEZIER_POINT_EDIT_BEHAVIOR::MakePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
aPoints.AddPoint( m_bezier.GetStart() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC1() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC2() );
|
||||
aPoints.AddPoint( m_bezier.GetEnd() );
|
||||
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_START ), aPoints.Point( BEZIER_CTRL_PT1 ) );
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_CTRL_PT2 ), aPoints.Point( BEZIER_END ) );
|
||||
}
|
||||
|
||||
void EDA_BEZIER_POINT_EDIT_BEHAVIOR::UpdatePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, BEZIER_MAX_POINTS );
|
||||
|
||||
aPoints.Point( BEZIER_START ).SetPosition( m_bezier.GetStart() );
|
||||
aPoints.Point( BEZIER_CTRL_PT1 ).SetPosition( m_bezier.GetBezierC1() );
|
||||
aPoints.Point( BEZIER_CTRL_PT2 ).SetPosition( m_bezier.GetBezierC2() );
|
||||
aPoints.Point( BEZIER_END ).SetPosition( m_bezier.GetEnd() );
|
||||
}
|
||||
|
||||
void EDA_BEZIER_POINT_EDIT_BEHAVIOR::UpdateItem( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems )
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, BEZIER_MAX_POINTS );
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( BEZIER_START ) ) )
|
||||
{
|
||||
m_bezier.SetStart( aPoints.Point( BEZIER_START ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT1 ) ) )
|
||||
{
|
||||
m_bezier.SetBezierC1( aPoints.Point( BEZIER_CTRL_PT1 ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT2 ) ) )
|
||||
{
|
||||
m_bezier.SetBezierC2( aPoints.Point( BEZIER_CTRL_PT2 ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_END ) ) )
|
||||
{
|
||||
m_bezier.SetEnd( aPoints.Point( BEZIER_END ).GetPosition() );
|
||||
}
|
||||
|
||||
m_bezier.RebuildBezierToSegmentsPointsList( ARC_HIGH_DEF );
|
||||
}
|
||||
|
||||
|
||||
void EDA_TABLECELL_POINT_EDIT_BEHAVIOR::MakePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
|
||||
}
|
||||
|
||||
|
||||
void EDA_TABLECELL_POINT_EDIT_BEHAVIOR::UpdatePoints( EDIT_POINTS& aPoints )
|
||||
{
|
||||
aPoints.Point( COL_WIDTH )
|
||||
.SetPosition( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
|
||||
aPoints.Point( ROW_HEIGHT )
|
||||
.SetPosition( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
|
||||
}
|
||||
|
@ -62,12 +62,6 @@ enum ARC_POINTS
|
||||
};
|
||||
|
||||
|
||||
enum CIRCLE_POINTS
|
||||
{
|
||||
CIRC_CENTER, CIRC_END
|
||||
};
|
||||
|
||||
|
||||
enum RECTANGLE_POINTS
|
||||
{
|
||||
RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT, RECT_CENTER
|
||||
@ -97,15 +91,6 @@ enum LINE_POINTS
|
||||
};
|
||||
|
||||
|
||||
enum BEZIER_POINTS
|
||||
{
|
||||
BEZIER_START,
|
||||
BEZIER_CTRL_PT1,
|
||||
BEZIER_CTRL_PT2,
|
||||
BEZIER_END
|
||||
};
|
||||
|
||||
|
||||
class LINE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
@ -249,85 +234,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class CIRCLE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
CIRCLE_POINT_EDIT_BEHAVIOR( SCH_SHAPE& aCircle ) :
|
||||
m_circle( aCircle )
|
||||
{
|
||||
wxASSERT( m_circle.GetShape() == SHAPE_T::CIRCLE );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.AddPoint( m_circle.GetPosition() );
|
||||
aPoints.AddPoint( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.Point( CIRC_CENTER ).SetPosition( m_circle.GetPosition() );
|
||||
aPoints.Point( CIRC_END ).SetPosition( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override
|
||||
{
|
||||
m_circle.SetPosition( aPoints.Point( CIRC_CENTER ).GetPosition() );
|
||||
m_circle.SetEnd( aPoints.Point( CIRC_END ).GetPosition() );
|
||||
|
||||
aUpdatedItems.push_back( &m_circle );
|
||||
}
|
||||
private:
|
||||
SCH_SHAPE& m_circle;
|
||||
};
|
||||
|
||||
|
||||
class BEZIER_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
BEZIER_POINT_EDIT_BEHAVIOR( SCH_SHAPE& aBezier ) :
|
||||
m_bezier( aBezier )
|
||||
{
|
||||
wxASSERT( m_bezier.GetShape() == SHAPE_T::BEZIER );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.AddPoint( m_bezier.GetStart() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC1() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC2() );
|
||||
aPoints.AddPoint( m_bezier.GetEnd() );
|
||||
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_START ), aPoints.Point( BEZIER_CTRL_PT1 ) );
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_END ), aPoints.Point( BEZIER_CTRL_PT2 ) );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.Point( BEZIER_START ).SetPosition( m_bezier.GetStart() );
|
||||
aPoints.Point( BEZIER_CTRL_PT1 ).SetPosition( m_bezier.GetBezierC1() );
|
||||
aPoints.Point( BEZIER_CTRL_PT2 ).SetPosition( m_bezier.GetBezierC2() );
|
||||
aPoints.Point( BEZIER_END ).SetPosition( m_bezier.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override
|
||||
{
|
||||
m_bezier.SetStart( aPoints.Point( BEZIER_START ).GetPosition() );
|
||||
m_bezier.SetBezierC1( aPoints.Point( BEZIER_CTRL_PT1 ).GetPosition() );
|
||||
m_bezier.SetBezierC2( aPoints.Point( BEZIER_CTRL_PT2 ).GetPosition() );
|
||||
m_bezier.SetEnd( aPoints.Point( BEZIER_END ).GetPosition() );
|
||||
|
||||
m_bezier.RebuildBezierToSegmentsPointsList( m_bezier.GetWidth() / 2 );
|
||||
|
||||
aUpdatedItems.push_back( &m_bezier );
|
||||
}
|
||||
private:
|
||||
SCH_SHAPE& m_bezier;
|
||||
};
|
||||
|
||||
|
||||
class BITMAP_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
@ -445,23 +351,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class TABLECELL_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
class SCH_TABLECELL_POINT_EDIT_BEHAVIOR : public EDA_TABLECELL_POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
TABLECELL_POINT_EDIT_BEHAVIOR( SCH_TABLECELL& aCell ) : m_cell( aCell ) {}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
SCH_TABLECELL_POINT_EDIT_BEHAVIOR( SCH_TABLECELL& aCell ) :
|
||||
EDA_TABLECELL_POINT_EDIT_BEHAVIOR( aCell ), m_cell( aCell )
|
||||
{
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.Point( COL_WIDTH )
|
||||
.SetPosition( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
|
||||
aPoints.Point( ROW_HEIGHT )
|
||||
.SetPosition( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
@ -974,7 +869,7 @@ void EE_POINT_EDITOR::makePointsAndBehavior( EDA_ITEM* aItem )
|
||||
m_editBehavior = std::make_unique<ARC_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
case SHAPE_T::CIRCLE:
|
||||
m_editBehavior = std::make_unique<CIRCLE_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
m_editBehavior = std::make_unique<EDA_CIRCLE_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
case SHAPE_T::RECTANGLE:
|
||||
m_editBehavior = std::make_unique<RECTANGLE_POINT_EDIT_BEHAVIOR>( *shape, *m_frame );
|
||||
@ -983,7 +878,7 @@ void EE_POINT_EDITOR::makePointsAndBehavior( EDA_ITEM* aItem )
|
||||
m_editBehavior = std::make_unique<EDA_POLYGON_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
case SHAPE_T::BEZIER:
|
||||
m_editBehavior = std::make_unique<BEZIER_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
m_editBehavior = std::make_unique<EDA_BEZIER_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
default:
|
||||
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
||||
@ -1007,7 +902,7 @@ void EE_POINT_EDITOR::makePointsAndBehavior( EDA_ITEM* aItem )
|
||||
case SCH_TABLECELL_T:
|
||||
{
|
||||
SCH_TABLECELL* cell = static_cast<SCH_TABLECELL*>( aItem );
|
||||
m_editBehavior = std::make_unique<TABLECELL_POINT_EDIT_BEHAVIOR>( *cell );
|
||||
m_editBehavior = std::make_unique<SCH_TABLECELL_POINT_EDIT_BEHAVIOR>( *cell );
|
||||
break;
|
||||
}
|
||||
case SCH_SHEET_T:
|
||||
|
@ -182,4 +182,143 @@ public:
|
||||
{
|
||||
wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Standard" segment editing behavior for EDA_SHAPE segments.
|
||||
*/
|
||||
class EDA_SEGMENT_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
EDA_SEGMENT_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aSegment ) : m_segment( aSegment )
|
||||
{
|
||||
wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override;
|
||||
|
||||
OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const override;
|
||||
|
||||
protected:
|
||||
enum SEGMENT_POINTS
|
||||
{
|
||||
SEGMENT_START,
|
||||
SEGMENT_END,
|
||||
|
||||
SEGMENT_MAX_POINTS,
|
||||
};
|
||||
|
||||
private:
|
||||
EDA_SHAPE& m_segment;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Standard" circle editing behavior for EDA_SHAPE circles.
|
||||
*/
|
||||
class EDA_CIRCLE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
EDA_CIRCLE_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aCircle ) : m_circle( aCircle )
|
||||
{
|
||||
wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override;
|
||||
|
||||
OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const override;
|
||||
|
||||
protected:
|
||||
enum CIRCLE_POINTS
|
||||
{
|
||||
CIRC_CENTER,
|
||||
CIRC_END,
|
||||
|
||||
CIRC_MAX_POINTS,
|
||||
};
|
||||
|
||||
private:
|
||||
EDA_SHAPE& m_circle;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Standard" bezier editing behavior for EDA_SHAPE beziers.
|
||||
*/
|
||||
class EDA_BEZIER_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier ) : m_bezier( aBezier )
|
||||
{
|
||||
wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override;
|
||||
|
||||
protected:
|
||||
enum BEZIER_POINTS
|
||||
{
|
||||
BEZIER_START,
|
||||
BEZIER_CTRL_PT1,
|
||||
BEZIER_CTRL_PT2,
|
||||
BEZIER_END,
|
||||
|
||||
BEZIER_MAX_POINTS
|
||||
};
|
||||
|
||||
private:
|
||||
EDA_SHAPE& m_bezier;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* "Standard" table-cell editing behavior.
|
||||
*
|
||||
* This works over the EDA_SHAPE basis of a SCH/PCB_TABLECELL.
|
||||
* The cells and tables themselves aren't (yet) polymorphic, so the implmentation
|
||||
* has to provide UpdateItem() to handle the actual update.
|
||||
*/
|
||||
class EDA_TABLECELL_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
EDA_TABLECELL_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aCell ) : m_cell( aCell )
|
||||
{
|
||||
// While PCB_TEXTBOXES are not always RECTANGLEs, they are when they
|
||||
// are TABLECELLs.
|
||||
wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override;
|
||||
|
||||
protected:
|
||||
enum TABLECELL_POINTS
|
||||
{
|
||||
COL_WIDTH,
|
||||
ROW_HEIGHT,
|
||||
|
||||
TABLECELL_MAX_POINTS,
|
||||
};
|
||||
|
||||
private:
|
||||
EDA_SHAPE& m_cell;
|
||||
};
|
@ -62,12 +62,6 @@ using namespace std::placeholders;
|
||||
const unsigned int PCB_POINT_EDITOR::COORDS_PADDING = pcbIUScale.mmToIU( 20 );
|
||||
|
||||
// Few constants to avoid using bare numbers for point indices
|
||||
enum SEG_POINTS
|
||||
{
|
||||
SEG_START, SEG_END
|
||||
};
|
||||
|
||||
|
||||
enum RECT_POINTS
|
||||
{
|
||||
RECT_TOP_LEFT,
|
||||
@ -110,52 +104,6 @@ enum TEXTBOX_POINT_COUNT
|
||||
};
|
||||
|
||||
|
||||
class SEGMENT_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
SEGMENT_POINT_EDIT_BEHAVIOR( PCB_SHAPE& aSegment ) : m_segment( aSegment )
|
||||
{
|
||||
wxASSERT( m_segment.GetShape() == SHAPE_T::SEGMENT );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.AddPoint( m_segment.GetStart() );
|
||||
aPoints.AddPoint( m_segment.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, 2 );
|
||||
|
||||
aPoints.Point( SEG_START ) = m_segment.GetStart();
|
||||
aPoints.Point( SEG_END ) = m_segment.GetEnd();
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, 2 );
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( SEG_START ) ) )
|
||||
m_segment.SetStart( aPoints.Point( SEG_START ).GetPosition() );
|
||||
|
||||
else if( isModified( aEditedPoint, aPoints.Point( SEG_END ) ) )
|
||||
m_segment.SetEnd( aPoints.Point( SEG_END ).GetPosition() );
|
||||
}
|
||||
|
||||
OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const override
|
||||
{
|
||||
// Select the other end of line
|
||||
return aPoints.Next( aEditedPoint )->GetPosition();
|
||||
}
|
||||
|
||||
private:
|
||||
PCB_SHAPE& m_segment;
|
||||
};
|
||||
|
||||
|
||||
class RECTANGLE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
@ -842,64 +790,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class CIRCLE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
enum CIRCLE_POINTS
|
||||
{
|
||||
CIRC_CENTER,
|
||||
CIRC_END,
|
||||
};
|
||||
|
||||
public:
|
||||
CIRCLE_POINT_EDIT_BEHAVIOR( PCB_SHAPE& aCircle ) : m_circle( aCircle )
|
||||
{
|
||||
wxASSERT( m_circle.GetShape() == SHAPE_T::CIRCLE );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.AddPoint( m_circle.GetCenter() );
|
||||
aPoints.AddPoint( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, 2 );
|
||||
|
||||
aPoints.Point( CIRC_CENTER ).SetPosition( m_circle.GetCenter() );
|
||||
aPoints.Point( CIRC_END ).SetPosition( m_circle.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, 2 );
|
||||
|
||||
const VECTOR2I& center = aPoints.Point( CIRC_CENTER ).GetPosition();
|
||||
const VECTOR2I& end = aPoints.Point( CIRC_END ).GetPosition();
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( CIRC_CENTER ) ) )
|
||||
{
|
||||
VECTOR2I moveVector = VECTOR2I( center.x, center.y ) - m_circle.GetCenter();
|
||||
m_circle.Move( moveVector );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_circle.SetEnd( VECTOR2I( end.x, end.y ) );
|
||||
}
|
||||
}
|
||||
|
||||
OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
|
||||
EDIT_POINTS& aPoints ) const override
|
||||
{
|
||||
return aPoints.Point( CIRC_CENTER ).GetPosition();
|
||||
}
|
||||
|
||||
private:
|
||||
PCB_SHAPE& m_circle;
|
||||
};
|
||||
|
||||
|
||||
class ZONE_POINT_EDIT_BEHAVIOR : public POLYGON_POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
public:
|
||||
@ -924,75 +814,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class BEZIER_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
enum BEZIER_POINTS
|
||||
{
|
||||
BEZIER_START,
|
||||
BEZIER_CTRL_PT1,
|
||||
BEZIER_CTRL_PT2,
|
||||
BEZIER_END,
|
||||
|
||||
BEZIER_MAX_POINTS
|
||||
};
|
||||
|
||||
public:
|
||||
BEZIER_POINT_EDIT_BEHAVIOR( PCB_SHAPE& aBezier ) : m_bezier( aBezier )
|
||||
{
|
||||
wxASSERT( m_bezier.GetShape() == SHAPE_T::BEZIER );
|
||||
}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
aPoints.AddPoint( m_bezier.GetStart() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC1() );
|
||||
aPoints.AddPoint( m_bezier.GetBezierC2() );
|
||||
aPoints.AddPoint( m_bezier.GetEnd() );
|
||||
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_START ), aPoints.Point( BEZIER_CTRL_PT1 ) );
|
||||
aPoints.AddIndicatorLine( aPoints.Point( BEZIER_CTRL_PT2 ), aPoints.Point( BEZIER_END ) );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, BEZIER_MAX_POINTS );
|
||||
|
||||
aPoints.Point( BEZIER_START ).SetPosition( m_bezier.GetStart() );
|
||||
aPoints.Point( BEZIER_CTRL_PT1 ).SetPosition( m_bezier.GetBezierC1() );
|
||||
aPoints.Point( BEZIER_CTRL_PT2 ).SetPosition( m_bezier.GetBezierC2() );
|
||||
aPoints.Point( BEZIER_END ).SetPosition( m_bezier.GetEnd() );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
std::vector<EDA_ITEM*>& aUpdatedItems ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, BEZIER_MAX_POINTS );
|
||||
|
||||
if( isModified( aEditedPoint, aPoints.Point( BEZIER_START ) ) )
|
||||
{
|
||||
m_bezier.SetStart( aPoints.Point( BEZIER_START ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT1 ) ) )
|
||||
{
|
||||
m_bezier.SetBezierC1( aPoints.Point( BEZIER_CTRL_PT1 ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT2 ) ) )
|
||||
{
|
||||
m_bezier.SetBezierC2( aPoints.Point( BEZIER_CTRL_PT2 ).GetPosition() );
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( BEZIER_END ) ) )
|
||||
{
|
||||
m_bezier.SetEnd( aPoints.Point( BEZIER_END ).GetPosition() );
|
||||
}
|
||||
|
||||
m_bezier.RebuildBezierToSegmentsPointsList( ARC_HIGH_DEF );
|
||||
}
|
||||
|
||||
private:
|
||||
PCB_SHAPE& m_bezier;
|
||||
};
|
||||
|
||||
|
||||
class REFERENCE_IMAGE_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
enum REFIMG_POINTS
|
||||
@ -1125,34 +946,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class TABLECELL_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR
|
||||
class PCB_TABLECELL_POINT_EDIT_BEHAVIOR : public EDA_TABLECELL_POINT_EDIT_BEHAVIOR
|
||||
{
|
||||
enum TABLECELL_POINTS
|
||||
{
|
||||
COL_WIDTH,
|
||||
ROW_HEIGHT,
|
||||
|
||||
TABLECELL_MAX_POINTS,
|
||||
};
|
||||
|
||||
public:
|
||||
TABLECELL_POINT_EDIT_BEHAVIOR( PCB_TABLECELL& aCell ) : m_cell( aCell ) {}
|
||||
|
||||
void MakePoints( EDIT_POINTS& aPoints ) override
|
||||
PCB_TABLECELL_POINT_EDIT_BEHAVIOR( PCB_TABLECELL& aCell ) :
|
||||
EDA_TABLECELL_POINT_EDIT_BEHAVIOR( aCell ), m_cell( aCell )
|
||||
{
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
|
||||
aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
|
||||
}
|
||||
|
||||
void UpdatePoints( EDIT_POINTS& aPoints ) override
|
||||
{
|
||||
CHECK_POINT_COUNT( aPoints, TABLECELL_MAX_POINTS );
|
||||
|
||||
aPoints.Point( COL_WIDTH )
|
||||
.SetPosition( m_cell.GetEndX(),
|
||||
m_cell.GetEndY() - m_cell.GetRectangleHeight() / 2 );
|
||||
aPoints.Point( ROW_HEIGHT )
|
||||
.SetPosition( m_cell.GetEndX() - m_cell.GetRectangleWidth() / 2, m_cell.GetEndY() );
|
||||
}
|
||||
|
||||
void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
|
||||
@ -1161,7 +960,6 @@ public:
|
||||
CHECK_POINT_COUNT( aPoints, TABLECELL_MAX_POINTS );
|
||||
|
||||
PCB_TABLE& table = static_cast<PCB_TABLE&>( *m_cell.GetParent() );
|
||||
|
||||
aCommit.Modify( &table );
|
||||
aUpdatedItems.push_back( &table );
|
||||
|
||||
@ -1175,7 +973,6 @@ public:
|
||||
colWidth -= table.GetColWidth( m_cell.GetColumn() + ii );
|
||||
|
||||
table.SetColWidth( m_cell.GetColumn() + m_cell.GetColSpan() - 1, colWidth );
|
||||
table.Normalize();
|
||||
}
|
||||
else if( isModified( aEditedPoint, aPoints.Point( ROW_HEIGHT ) ) )
|
||||
{
|
||||
@ -1187,8 +984,9 @@ public:
|
||||
rowHeight -= table.GetRowHeight( m_cell.GetRow() + ii );
|
||||
|
||||
table.SetRowHeight( m_cell.GetRow() + m_cell.GetRowSpan() - 1, rowHeight );
|
||||
table.Normalize();
|
||||
}
|
||||
|
||||
table.Normalize();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2110,7 +1908,7 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||
switch( shape->GetShape() )
|
||||
{
|
||||
case SHAPE_T::SEGMENT:
|
||||
m_editorBehavior = std::make_unique<SEGMENT_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
m_editorBehavior = std::make_unique<EDA_SEGMENT_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
case SHAPE_T::RECTANGLE:
|
||||
m_editorBehavior = std::make_unique<RECTANGLE_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
@ -2121,7 +1919,7 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||
break;
|
||||
|
||||
case SHAPE_T::CIRCLE:
|
||||
m_editorBehavior = std::make_unique<CIRCLE_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
m_editorBehavior = std::make_unique<EDA_CIRCLE_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
|
||||
case SHAPE_T::POLY:
|
||||
@ -2129,7 +1927,7 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||
break;
|
||||
|
||||
case SHAPE_T::BEZIER:
|
||||
m_editorBehavior = std::make_unique<BEZIER_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
m_editorBehavior = std::make_unique<EDA_BEZIER_POINT_EDIT_BEHAVIOR>( *shape );
|
||||
break;
|
||||
|
||||
default: // suppress warnings
|
||||
@ -2142,7 +1940,7 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||
case PCB_TABLECELL_T:
|
||||
{
|
||||
PCB_TABLECELL* cell = static_cast<PCB_TABLECELL*>( aItem );
|
||||
m_editorBehavior = std::make_unique<TABLECELL_POINT_EDIT_BEHAVIOR>( *cell );
|
||||
m_editorBehavior = std::make_unique<PCB_TABLECELL_POINT_EDIT_BEHAVIOR>( *cell );
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user