Commit 3b56ea67 authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: fix crash when changing a label type to a global label during creation.

Pcbnew: code cleaning in polygons
parent ef39c5f3
......@@ -230,6 +230,10 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent )
newtext->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
m_canvas->CrossHairOn( &dc ); // redraw schematic cursor
// if the old item is the current schematic item, replace it by the new text:
if( screen->GetCurItem() == text )
screen->SetCurItem( newtext );
if( text->IsNew() )
{
// if the previous text is new, no undo command to prepare here
......
......@@ -950,8 +950,6 @@ void SCH_SHEET::renumberPins()
void SCH_SHEET::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
// Using BOOST_FOREACH here creates problems (bad pointer value to pinsheet).
// I do not know why.
for( unsigned ii = 0; ii < GetPins().size(); ii++ )
{
SCH_SHEET_PIN &pinsheet = GetPins()[ii];
......
......@@ -1115,11 +1115,9 @@ public:
* area_to_test must be after area_ref in m_ZoneDescriptorList
* @param area_ref = area reference
* @param area_to_test = area to compare for intersection calculations
* @return : 0 if no intersection
* 1 if intersection
* 2 if arcs intersect
* @return : false if no intersection, true if intersection
*/
int TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test );
bool TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test );
/**
* Function CombineAreas
......
This diff is collapsed.
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 17 2012)
// C++ code generated with wxFormBuilder (version Apr 10 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
......@@ -46,8 +46,8 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
void _wxFB_OnCornerSmoothingModeChoice( wxCommandEvent& event ){ OnCornerSmoothingModeChoice( event ); }
void _wxFB_OnPadsInZoneClick( wxCommandEvent& event ){ OnPadsInZoneClick( event ); }
void _wxFB_ExportSetupToOtherCopperZones( wxCommandEvent& event ){ ExportSetupToOtherCopperZones( event ); }
void _wxFB_OnButtonOkClick( wxCommandEvent& event ){ OnButtonOkClick( event ); }
void _wxFB_OnButtonCancelClick( wxCommandEvent& event ){ OnButtonCancelClick( event ); }
void _wxFB_OnButtonOkClick( wxCommandEvent& event ){ OnButtonOkClick( event ); }
protected:
......@@ -108,8 +108,9 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
wxStaticText* m_staticText15;
wxChoice* m_OutlineAppearanceCtrl;
wxButton* m_ExportSetupButton;
wxButton* m_OkButton;
wxButton* m_ButtonCancel;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
......@@ -119,13 +120,13 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
virtual void OnCornerSmoothingModeChoice( wxCommandEvent& event ) { event.Skip(); }
virtual void OnPadsInZoneClick( wxCommandEvent& event ) { event.Skip(); }
virtual void ExportSetupToOtherCopperZones( wxCommandEvent& event ) { event.Skip(); }
virtual void OnButtonOkClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnButtonCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnButtonOkClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_COPPER_ZONE_BASE( wxWindow* parent, wxWindowID id = ID_DIALOG_COPPER_ZONE_BASE, const wxString& title = _("Zone Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 567,500 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_COPPER_ZONE_BASE( wxWindow* parent, wxWindowID id = ID_DIALOG_COPPER_ZONE_BASE, const wxString& title = _("Copper Zone Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 567,500 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_COPPER_ZONE_BASE();
};
......
......@@ -276,12 +276,12 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
// check area2 against curr_area
if( curr_area->utility || area2->utility || aUseUtility == false )
{
int ret = TestAreaIntersection( curr_area, area2 );
bool ret = TestAreaIntersection( curr_area, area2 );
if( ret == 1 )
if( ret )
ret = CombineAreas( aDeletedList, curr_area, area2 );
if( ret == 1 )
if( ret )
{
mod_ia1 = true;
modified = true;
......@@ -306,8 +306,6 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
*/
bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
{
CPolyLine* poly1 = area_to_test->m_Poly;
for( unsigned ia2 = 0; ia2 < m_ZoneDescriptorList.size(); ia2++ )
{
ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2];
......@@ -330,96 +328,9 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
if( area_to_test->GetIsKeepout() != area2->GetIsKeepout() )
continue;
CPolyLine* poly2 = area2->m_Poly;
// test bounding rects
CRect b1 = poly1->GetCornerBounds();
CRect b2 = poly2->GetCornerBounds();
if( b1.bottom > b2.top
|| b1.top < b2.bottom
|| b1.left > b2.right
|| b1.right < b2.left )
continue;
// test for intersecting segments
for( int icont1 = 0; icont1<poly1->GetContoursCount(); icont1++ )
{
int is1 = poly1->GetContourStart( icont1 );
int ie1 = poly1->GetContourEnd( icont1 );
for( int ic1 = is1; ic1<=ie1; ic1++ )
{
int xi1 = poly1->GetX( ic1 );
int yi1 = poly1->GetY( ic1 );
int xf1, yf1;
if( ic1 < ie1 )
{
xf1 = poly1->GetX( ic1 + 1 );
yf1 = poly1->GetY( ic1 + 1 );
}
else
{
xf1 = poly1->GetX( is1 );
yf1 = poly1->GetY( is1 );
}
for( int icont2 = 0; icont2 < poly2->GetContoursCount(); icont2++ )
{
int is2 = poly2->GetContourStart( icont2 );
int ie2 = poly2->GetContourEnd( icont2 );
for( int ic2 = is2; ic2<=ie2; ic2++ )
{
int xi2 = poly2->GetX( ic2 );
int yi2 = poly2->GetY( ic2 );
int xf2, yf2;
if( ic2 < ie2 )
{
xf2 = poly2->GetX( ic2 + 1 );
yf2 = poly2->GetY( ic2 + 1 );
}
else
{
xf2 = poly2->GetX( is2 );
yf2 = poly2->GetY( is2 );
}
int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1,
xi2, yi2, xf2, yf2 );
if( n_int )
if( TestAreaIntersection( area_to_test, area2 ) )
return true;
}
}
}
}
// If a contour is inside an other contour, no segments intersects, but the zones can
// be combined test a corner inside an outline (only one corner is enought)
for( int ic2 = 0; ic2 < poly2->GetNumCorners(); ic2++ )
{
int x = poly2->GetX( ic2 );
int y = poly2->GetY( ic2 );
if( poly1->TestPointInside( x, y ) )
{
return true;
}
}
for( int ic1 = 0; ic1 < poly1->GetNumCorners(); ic1++ )
{
int x = poly1->GetX( ic1 );
int y = poly1->GetY( ic1 );
if( poly2->TestPointInside( x, y ) )
{
return true;
}
}
}
return false;
}
......@@ -431,14 +342,13 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
* area_to_test must be after area_ref in m_ZoneDescriptorList
* @param area_ref = area reference
* @param area_to_test = area to compare for intersection calculations
* @return : 0 if no intersection
* 1 if intersection
* @return : false if no intersection, true if intersection
*/
int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test )
bool BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test )
{
// see if areas are on same layer
if( area_ref->GetLayer() != area_to_test->GetLayer() )
return 0;
return false;
CPolyLine* poly1 = area_ref->m_Poly;
CPolyLine* poly2 = area_to_test->m_Poly;
......@@ -449,11 +359,9 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
if( b1.bottom > b2.top || b1.top < b2.bottom ||
b1.left > b2.right || b1.right < b2.left )
return 0;
return false;
// now test for intersecting segments
bool bInt = false;
for( int icont1 = 0; icont1<poly1->GetContoursCount(); icont1++ )
{
int is1 = poly1->GetContourStart( icont1 );
......@@ -498,22 +406,17 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
yf2 = poly2->GetY( is2 );
}
int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1,
bool intersect = FindSegmentIntersections( xi1, yi1, xf1, yf1,
xi2, yi2, xf2, yf2 );
if( n_int )
{
bInt = true;
break;
}
if( intersect )
return true;
}
}
}
}
if( !bInt )
{
// If a contour is inside an other contour, no segments intersects, but the zones
// can be combined test a corner inside an outline (only one corner is enought)
// can be combined if a corner is inside an outline (only one corner is enought)
for( int ic2 = 0; ic2 < poly2->GetNumCorners(); ic2++ )
{
int x = poly2->GetX( ic2 );
......@@ -537,9 +440,6 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
}
return 0;
}
return 1;
}
......
......@@ -453,7 +453,96 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
*/
int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
{
#if 1
return NormalizeWithKbool( aNewPolygonList );
#else // Do NOT use this code: it does not yet work
unsigned corners_count = m_CornersList.size();
KI_POLYGON_SET polysholes;
KI_POLYGON_WITH_HOLES mainpoly;
std::vector<KI_POLY_POINT> cornerslist;
KI_POLYGON_WITH_HOLES_SET outlines;
KI_POLYGON poly_tmp;
unsigned ic = 0;
// enter main outline
while( ic < corners_count )
{
const CPolyPt& corner = m_CornersList[ic++];
cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) );
if( corner.end_contour )
break;
}
mainpoly.set( cornerslist.begin(), cornerslist.end() );
outlines.push_back( mainpoly );
outlines &= mainpoly;
// Enter holes
while( ic < corners_count )
{
cornerslist.clear();
{
while( ic < corners_count )
{
const CPolyPt& corner = m_CornersList[ic++];
cornerslist.push_back( KI_POLY_POINT( corner.x, corner.y ) );
if( corner.end_contour )
break;
}
bpl::set_points( poly_tmp, cornerslist.begin(), cornerslist.end() );
polysholes.push_back( poly_tmp );
}
}
outlines -= polysholes;
// copy polygon with holes to destination
RemoveAllContours();
for( unsigned ii = 0; ii < outlines.size(); ii++ )
{
CPolyLine* polyline = this;
if( ii > 0 )
{
polyline = new CPolyLine;
polyline->SetLayer( GetLayer() );
polyline->SetHatchStyle( GetHatchStyle() );
polyline->SetHatchPitch( GetHatchPitch() );
aNewPolygonList->push_back( polyline );
}
KI_POLYGON_WITH_HOLES& curr_poly = outlines[ii];
KI_POLYGON_WITH_HOLES::iterator_type corner = curr_poly.begin();
// enter main contour
while( corner != curr_poly.end() )
{
polyline->AppendCorner( corner->x(), corner->y() );
corner++;
}
polyline->CloseLastContour();
// add holes (set of polygons)
KI_POLYGON_WITH_HOLES::iterator_holes_type hole = curr_poly.begin_holes();
while( hole != curr_poly.end_holes() )
{
KI_POLYGON::iterator_type hole_corner = hole->begin();
// create area with external contour: Recreate only area edges, NOT holes
while( hole_corner != hole->end() )
{
polyline->AppendCorner( hole_corner->x(), hole_corner->y() );
hole_corner++;
}
polyline->CloseLastContour();
hole++;
}
}
return outlines.size();
#endif
}
......@@ -1526,8 +1615,8 @@ void ConvertPolysListWithHolesToOnePolygon( const std::vector<CPolyPt>& aPolysL
std::vector<CPolyPt>& aOnePolyList )
{
unsigned corners_count = aPolysListWithHoles.size();
int polycount = 0;
int polycount = 0;
for( unsigned ii = 0; ii < corners_count; ii++ )
{
const CPolyPt& corner = aPolysListWithHoles[ii];
......@@ -1536,8 +1625,8 @@ void ConvertPolysListWithHolesToOnePolygon( const std::vector<CPolyPt>& aPolysL
polycount++;
}
// If polycount<= 1, there is no holes found.
if( polycount<= 1 )
// If polycount<= 1, there is no holes found, and therefore just copy the polygon.
if( polycount <= 1 )
{
aOnePolyList = aPolysListWithHoles;
return;
......@@ -1587,7 +1676,6 @@ void ConvertPolysListWithHolesToOnePolygon( const std::vector<CPolyPt>& aPolysL
// We should have only one polygon in list
wxASSERT( mainpoly.size() != 1 );
{
KI_POLYGON& poly_nohole = mainpoly[0];
CPolyPt corner( 0, 0, false );
......@@ -1603,7 +1691,6 @@ void ConvertPolysListWithHolesToOnePolygon( const std::vector<CPolyPt>& aPolysL
corner.end_contour = true;
aOnePolyList.pop_back();
aOnePolyList.push_back( corner );
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment