Skip to content

Commit

Permalink
DRAWSEGMENT fix crash when trying to copy a empty polygon.
Browse files Browse the repository at this point in the history
SHAPE_POLY_SET: fix crash in VertexCount when it is a empty poly set, or when params are incorrect.

minor other fixes:
warning in degug mode in dialog_dxf_import_base.cpp
pcb_painter.cpp: remove a useless debug line.
  • Loading branch information
jp-charras committed Oct 25, 2017
1 parent 73c88bd commit 78ec983
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 20 deletions.
12 changes: 9 additions & 3 deletions common/geometry/shape_poly_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ void SHAPE_POLY_SET::InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex )

int SHAPE_POLY_SET::VertexCount( int aOutline , int aHole ) const
{
if( aOutline < 0 )
if( m_polys.size() == 0 ) // Empty poly set
return 0;

if( aOutline < 0 ) // Use last outline
aOutline += m_polys.size();

int idx;
Expand All @@ -230,8 +233,11 @@ int SHAPE_POLY_SET::VertexCount( int aOutline , int aHole ) const
else
idx = aHole + 1;

assert ( aOutline < (int)m_polys.size() );
assert ( idx < (int)m_polys[aOutline].size() );
if( aOutline >= (int)m_polys.size() ) // not existing outline
return 0;

if( idx >= (int)m_polys[aOutline].size() ) // not existing hole
return 0;

return m_polys[aOutline][idx].PointCount();
}
Expand Down
9 changes: 6 additions & 3 deletions include/geometry/shape_poly_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,11 @@ class SHAPE_POLY_SET : public SHAPE
///> Returns the number of holes in a given outline
int HoleCount( int aOutline ) const
{
if( (aOutline > (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
return 0;

// the first polygon in m_polys[aOutline] is the main contour,
// only others are holes:
return m_polys[aOutline].size() - 1;
}

Expand Down Expand Up @@ -1053,9 +1056,9 @@ class SHAPE_POLY_SET : public SHAPE
POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
int aIndex, int aSegments = -1 );

typedef std::vector<POLYGON> Polyset;
typedef std::vector<POLYGON> POLYSET;

Polyset m_polys;
POLYSET m_polys;
};

#endif
5 changes: 4 additions & 1 deletion pcbnew/class_drawsegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const
break;

case S_POLYGON:
if( m_Poly.IsEmpty() )
break;
{
wxPoint p_end;
MODULE* module = GetParentModule();
Expand Down Expand Up @@ -442,6 +444,7 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const
p_end.y = std::max( p_end.y, pt.y );
}
}

bbox.SetEnd( p_end );
break;
}
Expand Down Expand Up @@ -748,7 +751,7 @@ const std::vector<wxPoint> DRAWSEGMENT::GetPolyPoints() const
{
std::vector<wxPoint> rv;

if( m_Poly.VertexCount() > 0 )
if( !m_Poly.IsEmpty() )
{
for ( auto iter = m_Poly.CIterate(); iter; iter++ )
{
Expand Down
3 changes: 3 additions & 0 deletions pcbnew/class_edge_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
break;

case S_POLYGON:
if( m_Poly.IsEmpty() )
break;

{
// We must compute absolute coordinates from m_PolyPoints
// which are relative to module position, orientation 0
Expand Down
4 changes: 2 additions & 2 deletions pcbnew/import_dxf/dialog_dxf_import.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<property name="minimum_size"></property>
<property name="name">DIALOG_DXF_IMPORT_BASE</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="size">455,297</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Import DXF File</property>
Expand Down Expand Up @@ -1124,7 +1124,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">1</property>
<object class="wxBitmapComboBox" expanded="1">
<property name="BottomDockable">1</property>
Expand Down
23 changes: 18 additions & 5 deletions pcbnew/import_dxf/dialog_dxf_import_base.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
Expand Down Expand Up @@ -56,7 +56,14 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,
bSizer6->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

m_DXFPCBXCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 );
m_DXFPCBXCoord->SetMaxLength( 10 );
#ifdef __WXGTK__
if ( !m_DXFPCBXCoord->HasFlag( wxTE_MULTILINE ) )
{
m_DXFPCBXCoord->SetMaxLength( 10 );
}
#else
m_DXFPCBXCoord->SetMaxLength( 10 );
#endif
m_DXFPCBXCoord->SetToolTip( _("DXF origin on PCB Grid, X Coordinate") );

bSizer6->Add( m_DXFPCBXCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
Expand All @@ -72,7 +79,14 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,
bSizer7->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

m_DXFPCBYCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 );
m_DXFPCBYCoord->SetMaxLength( 10 );
#ifdef __WXGTK__
if ( !m_DXFPCBYCoord->HasFlag( wxTE_MULTILINE ) )
{
m_DXFPCBYCoord->SetMaxLength( 10 );
}
#else
m_DXFPCBYCoord->SetMaxLength( 10 );
#endif
m_DXFPCBYCoord->SetToolTip( _("DXF origin on PCB Grid, Y Coordinate") );

bSizer7->Add( m_DXFPCBYCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
Expand Down Expand Up @@ -112,7 +126,7 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,
bSizer8->Add( m_staticTextBrdlayer, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 );

m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
bSizer8->Add( m_SelLayerBox, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 );
bSizer8->Add( m_SelLayerBox, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );


bSizerMain->Add( bSizer8, 0, wxALL|wxEXPAND, 5 );
Expand All @@ -132,7 +146,6 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,

this->SetSizer( bSizerMain );
this->Layout();
bSizerMain->Fit( this );

this->Centre( wxBOTH );

Expand Down
4 changes: 2 additions & 2 deletions pcbnew/import_dxf/dialog_dxf_import_base.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
Expand Down Expand Up @@ -69,7 +69,7 @@ class DIALOG_DXF_IMPORT_BASE : public DIALOG_SHIM

public:

DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import DXF File"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import DXF File"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 455,297 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_DXF_IMPORT_BASE();

};
Expand Down
5 changes: 1 addition & 4 deletions pcbnew/pcb_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,11 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
break;

case S_RECT:
wxASSERT_MSG( false, wxT( "Not tested yet" ) );
wxASSERT_MSG( false, "Not tested yet" );
m_gal->DrawRectangle( start, end );
break;

case S_ARC:
printf( "S_ARC st %f end %f angle %f\n",
aSegment->GetArcAngleStart()/10.0, (aSegment->GetArcAngleStart() + aSegment->GetAngle())/10.0,
aSegment->GetAngle()/10.0 );
m_gal->DrawArcSegment( start, aSegment->GetRadius(),
DECIDEG2RAD( aSegment->GetArcAngleStart() ),
DECIDEG2RAD( aSegment->GetArcAngleStart() + aSegment->GetAngle() ),
Expand Down
1 change: 1 addition & 0 deletions pcbnew/tools/drawing_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
modSeg->SetBezControl2( seg->GetBezControl2() );
modSeg->SetBezierPoints( seg->GetBezierPoints() );
modSeg->SetPolyPoints( seg->GetPolyPoints() );
modSeg->SetLocalCoord();
converted = modSeg;
break;
}
Expand Down

0 comments on commit 78ec983

Please sign in to comment.