Commit 4ff3a78d authored by jean-pierre charras's avatar jean-pierre charras

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

Pcbnew: code cleaning in polygon functions
parents 4d2def35 899d23d4
......@@ -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,95 +328,8 @@ 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 )
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;
}
}
if( TestAreaIntersection( area_to_test, area2 ) )
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,48 +406,40 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
yf2 = poly2->GetY( is2 );
}
int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1,
xi2, yi2, xf2, yf2 );
if( n_int )
{
bInt = true;
break;
}
bool intersect = FindSegmentIntersections( xi1, yi1, xf1, yf1,
xi2, yi2, xf2, yf2 );
if( intersect )
return true;
}
}
}
}
if( !bInt )
// If a contour is inside an other contour, no segments intersects, but the zones
// can be combined if a corner is inside an outline (only one corner is enought)
for( int ic2 = 0; ic2 < poly2->GetNumCorners(); ic2++ )
{
// 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 );
int x = poly2->GetX( ic2 );
int y = poly2->GetY( ic2 );
if( poly1->TestPointInside( x, y ) )
{
return 1;
}
if( poly1->TestPointInside( x, y ) )
{
return 1;
}
}
for( int ic1 = 0; ic1 < poly1->GetNumCorners(); ic1++ )
{
int x = poly1->GetX( ic1 );
int y = poly1->GetY( ic1 );
for( int ic1 = 0; ic1 < poly1->GetNumCorners(); ic1++ )
{
int x = poly1->GetX( ic1 );
int y = poly1->GetY( ic1 );
if( poly2->TestPointInside( x, y ) )
{
return 1;
}
if( poly2->TestPointInside( x, y ) )
{
return 1;
}
return 0;
}
return 1;
return 0;
}
......
......@@ -24,7 +24,6 @@ CPolyLine::CPolyLine()
m_hatchStyle = NO_HATCH;
m_hatchPitch = 0;
m_layer = 0;
m_width = 0;
m_utility = 0;
m_Kbool_Poly_Engine = NULL;
}
......@@ -135,9 +134,7 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList )
else if( aExtraPolyList ) // a new outside contour is found: create a new CPolyLine
{
polyline = new CPolyLine;
polyline->SetLayer( GetLayer() );
polyline->SetHatchStyle( GetHatchStyle() );
polyline->SetHatchPitch( GetHatchPitch() );
polyline->ImportSettings( this );
aExtraPolyList->push_back( polyline ); // put it in array
bool first = true;
......@@ -456,6 +453,16 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
return NormalizeWithKbool( aNewPolygonList );
}
/**
* Function ImportSettings
* Copy settings (layer, hatch styles) from aPoly
*/
void CPolyLine::ImportSettings( const CPolyLine * aPoly )
{
SetLayer( aPoly->GetLayer() );
SetHatchStyle( aPoly->GetHatchStyle() );
SetHatchPitch( aPoly->GetHatchPitch() );
}
/* initialize a contour
* set layer, hatch style, and starting point
......@@ -842,11 +849,6 @@ int CPolyLine::GetEndContour( int ic )
CRect CPolyLine::GetBounds()
{
CRect r = GetCornerBounds();
r.left -= m_width / 2;
r.right += m_width / 2;
r.bottom -= m_width / 2;
r.top += m_width / 2;
return r;
}
......@@ -1526,8 +1528,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 +1538,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,23 +1589,21 @@ 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 );
for( unsigned jj = 0; jj < poly_nohole.size(); jj++ )
{
KI_POLY_POINT point = *(poly_nohole.begin() + jj);
corner.x = point.x();
corner.y = point.y();
corner.end_contour = false;
aOnePolyList.push_back( corner );
}
KI_POLYGON& poly_nohole = mainpoly[0];
CPolyPt corner( 0, 0, false );
corner.end_contour = true;
aOnePolyList.pop_back();
for( unsigned jj = 0; jj < poly_nohole.size(); jj++ )
{
KI_POLY_POINT point = *(poly_nohole.begin() + jj);
corner.x = point.x();
corner.y = point.y();
corner.end_contour = false;
aOnePolyList.push_back( corner );
}
corner.end_contour = true;
aOnePolyList.pop_back();
aOnePolyList.push_back( corner );
}
/**
......
......@@ -108,6 +108,13 @@ public:
CPolyLine();
~CPolyLine();
/**
* Function ImportSettings
* Copy settings (layer, hatch styles) from aPoly
* @param aPoly is the CPolyLine to import settings
*/
void ImportSettings( const CPolyLine * aPoly );
// functions for modifying the CPolyLine contours
/* initialize a contour
......@@ -176,15 +183,15 @@ public:
// access functions
void SetLayer( int aLayer ) { m_layer = aLayer; }
int GetLayer() { return m_layer; }
int GetNumCorners();
int GetNumSides();
int GetClosed();
int GetContoursCount();
int GetContour( int ic );
int GetContourStart( int icont );
int GetContourEnd( int icont );
int GetContourSize( int icont );
int GetLayer() const { return m_layer; }
int GetNumCorners();
int GetNumSides();
int GetClosed();
int GetContoursCount();
int GetContour( int ic );
int GetContourStart( int icont );
int GetContourEnd( int icont );
int GetContourSize( int icont );
int GetX( int ic ) const { return m_CornersList[ic].x; }
int GetY( int ic ) const { return m_CornersList[ic].y; }
......@@ -193,13 +200,13 @@ public:
int GetEndContour( int ic );
int GetUtility( int ic ) { return m_CornersList[ic].m_utility; };
int GetUtility( int ic ) const { return m_CornersList[ic].m_utility; };
void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; };
int GetHatchPitch() { return m_hatchPitch; }
int GetHatchPitch() const { return m_hatchPitch; }
static int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils
enum HATCH_STYLE GetHatchStyle() { return m_hatchStyle; }
enum HATCH_STYLE GetHatchStyle() const { return m_hatchStyle; }
void SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
{
SetHatchPitch( aHatchPitch );
......@@ -286,7 +293,6 @@ public:
private:
int m_layer; // layer to draw on
int m_width; // lines width when drawing. Provided but not really used
enum HATCH_STYLE m_hatchStyle; // hatch style, see enum above
int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines
// and the len of eacvh segment
......
......@@ -59,7 +59,6 @@ typedef bpl::polygon_with_holes_data<int> KI_POLYGON_WITH_HOLES;
* is always stored in a KI_POLYGON_WITH_HOLES_SET, because these operations
* can create many separate polygons with holespolygons
*/
typedef std::vector<KI_POLYGON_WITH_HOLES> KI_POLYGON_WITH_HOLES_SET;
......
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