Forbid drawing self-intersecting polygons.
This commit is contained in:
parent
7129dcef91
commit
4da47f2c01
|
@ -387,11 +387,8 @@ bool SHAPE_POLY_SET::GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int*
|
|||
|
||||
bool SHAPE_POLY_SET::IsPolygonSelfIntersecting( int aPolygonIndex )
|
||||
{
|
||||
// Get polygon
|
||||
const POLYGON poly = CPolygon( aPolygonIndex );
|
||||
|
||||
SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
|
||||
SEGMENT_ITERATOR innerIterator;
|
||||
SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
|
||||
SEGMENT_ITERATOR innerIterator;
|
||||
|
||||
for( iterator = IterateSegmentsWithHoles( aPolygonIndex ); iterator; iterator++ )
|
||||
{
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
POLYGON_GEOM_MANAGER::POLYGON_GEOM_MANAGER( CLIENT& aClient ):
|
||||
m_client( aClient ),
|
||||
m_leaderMode( LEADER_MODE::DIRECT )
|
||||
m_leaderMode( LEADER_MODE::DIRECT ),
|
||||
m_intersectionsAllowed( false )
|
||||
{}
|
||||
|
||||
|
||||
|
@ -52,6 +53,17 @@ bool POLYGON_GEOM_MANAGER::AddPoint( const VECTOR2I& aPt )
|
|||
m_lockedPoints.Append( aPt );
|
||||
}
|
||||
|
||||
// check for self-intersections (line chain needs to be set as closed for proper checks)
|
||||
m_lockedPoints.SetClosed( true );
|
||||
bool selfIntersect = !!m_lockedPoints.SelfIntersecting();
|
||||
m_lockedPoints.SetClosed( false );
|
||||
|
||||
if( !m_intersectionsAllowed && selfIntersect )
|
||||
{
|
||||
m_lockedPoints.Remove( m_lockedPoints.PointCount() - 1 );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_client.OnGeometryChange( *this );
|
||||
return true;
|
||||
}
|
||||
|
@ -117,8 +129,6 @@ void POLYGON_GEOM_MANAGER::Reset()
|
|||
void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER_MODE aModifier )
|
||||
{
|
||||
wxCHECK( m_lockedPoints.PointCount() > 0, /*void*/ );
|
||||
SHAPE_LINE_CHAIN newChain;
|
||||
|
||||
const VECTOR2I& lastPt = m_lockedPoints.CLastPoint();
|
||||
|
||||
if( m_leaderMode == LEADER_MODE::DEG45 || aModifier == LEADER_MODE::DEG45 )
|
||||
|
@ -129,6 +139,7 @@ void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER
|
|||
|
||||
// Can also add chain back to start, but this rearely produces
|
||||
// usable result
|
||||
//SHAPE_LINE_CHAIN newChain;
|
||||
//DIRECTION_45 directionToStart( aEndPoint - m_lockedPoints.front() );
|
||||
//newChain.Append( directionToStart.BuildInitialTrace( aEndPoint, m_lockedPoints.front() ) );
|
||||
}
|
||||
|
|
|
@ -95,6 +95,24 @@ public:
|
|||
*/
|
||||
void SetLeaderMode( LEADER_MODE aMode );
|
||||
|
||||
/**
|
||||
* Enables/disables self-intersecting polygons.
|
||||
* @param aEnabled true if self-intersecting polygons are enabled.
|
||||
*/
|
||||
void AllowIntersections( bool aEnabled )
|
||||
{
|
||||
m_intersectionsAllowed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether self-intersecting polygons are enabled.
|
||||
* @return true if self-intersecting polygons are enabled.
|
||||
*/
|
||||
bool IntersectionsAllowed() const
|
||||
{
|
||||
return m_intersectionsAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current cursor position
|
||||
*/
|
||||
|
@ -155,6 +173,9 @@ private:
|
|||
///> The current mode of the leader line
|
||||
LEADER_MODE m_leaderMode;
|
||||
|
||||
///> Flag enabling self-intersecting polygons
|
||||
bool m_intersectionsAllowed;
|
||||
|
||||
///> Point that have been "locked in"
|
||||
SHAPE_LINE_CHAIN m_lockedPoints;
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include <bitmaps.h>
|
||||
#include <hotkeys.h>
|
||||
#include <painter.h>
|
||||
#include <status_popup.h>
|
||||
|
||||
#include <preview_items/arc_assistant.h>
|
||||
|
||||
|
@ -658,6 +659,7 @@ int DRAWING_TOOL::DrawZoneCutout( const TOOL_EVENT& aEvent )
|
|||
return drawZone( false, ZONE_MODE::CUTOUT );
|
||||
}
|
||||
|
||||
|
||||
int DRAWING_TOOL::DrawGraphicPolygon( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::GRAPHIC_POLYGON );
|
||||
|
@ -1251,6 +1253,7 @@ void DRAWING_TOOL::runPolygonEventLoop( POLYGON_GEOM_MANAGER& polyGeomMgr )
|
|||
{
|
||||
auto& controls = *getViewControls();
|
||||
bool started = false;
|
||||
STATUS_TEXT_POPUP status( m_frame );
|
||||
|
||||
while( OPT_TOOL_EVENT evt = Wait() )
|
||||
{
|
||||
|
@ -1296,6 +1299,7 @@ void DRAWING_TOOL::runPolygonEventLoop( POLYGON_GEOM_MANAGER& polyGeomMgr )
|
|||
controls.SetAutoPan( false );
|
||||
controls.CaptureCursor( false );
|
||||
}
|
||||
|
||||
// adding a corner
|
||||
else if( polyGeomMgr.AddPoint( cursorPos ) )
|
||||
{
|
||||
|
@ -1306,6 +1310,16 @@ void DRAWING_TOOL::runPolygonEventLoop( POLYGON_GEOM_MANAGER& polyGeomMgr )
|
|||
controls.CaptureCursor( true );
|
||||
}
|
||||
}
|
||||
else if( started )
|
||||
{
|
||||
status.SetTextColor( wxColour( 255, 0, 0 ) );
|
||||
status.SetText( _( "Self-intersecting polygons are not allowed" ) );
|
||||
wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
|
||||
status.Move( p );
|
||||
status.Popup( m_frame );
|
||||
status.Expire( 1500 );
|
||||
}
|
||||
|
||||
}
|
||||
else if( evt->IsAction( &deleteLastPoint ) )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue