From ac1386a5a263f8314f7d677839155b07a687dace Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 14 May 2013 20:47:01 +0200 Subject: [PATCH] Pcbnew: fix bug 1179877, due a bad default copy constructor, after my changes about CPOLYGONS_LIST class. More about CPOLYGONS_LIST work. --- 3d-viewer/3d_draw.cpp | 14 ++++---- eeschema/sch_screen.cpp | 7 ++-- ...board_items_to_polygon_shape_transform.cpp | 8 ++--- pcbnew/class_zone.cpp | 12 +++---- pcbnew/class_zone.h | 2 +- pcbnew/zone_filling_algorithm.cpp | 4 +-- ...nvert_brd_items_to_polygons_with_Boost.cpp | 12 +++---- polygon/PolyLine.cpp | 32 +++++++++++-------- polygon/PolyLine.h | 16 +++++++--- 9 files changed, 59 insertions(+), 48 deletions(-) diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index ef303e55df..1c65aa0218 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -182,9 +182,9 @@ void EDA_3D_CANVAS::BuildBoard3DView() if( !g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) continue; - bufferPolys.clear(); - bufferZonesPolys.clear(); - currLayerHoles.clear(); + bufferPolys.RemoveAllContours(); + bufferZonesPolys.RemoveAllContours(); + currLayerHoles.RemoveAllContours(); // Draw tracks: for( TRACK* track = pcb->m_Track; track != NULL; track = track->Next() ) @@ -308,7 +308,7 @@ void EDA_3D_CANVAS::BuildBoard3DView() SetGLColor( color ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); - bufferPolys.clear(); + bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, @@ -346,7 +346,7 @@ void EDA_3D_CANVAS::BuildBoard3DView() if( !g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) continue; - bufferPolys.clear(); + bufferPolys.RemoveAllContours(); for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() ) { @@ -429,7 +429,7 @@ void EDA_3D_CANVAS::BuildBoard3DView() SetGLColor( color ); glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); - bufferPolys.clear(); + bufferPolys.RemoveAllContours(); bufferPolys.ImportFrom( currLayerPolyset ); Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos, thickness, g_Parm_3D_Visu.m_BiuTo3Dunits ); @@ -480,7 +480,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() 0.0F ); // Draw Board: -// For testing purpose only display calculation time to generate 3D data +// For testing purpose only, display calculation time to generate 3D data // #define PRINT_CALCULATION_TIME #ifdef PRINT_CALCULATION_TIME diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 258c3f3385..3d1a25f606 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -496,9 +496,8 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) bool SCH_SCREEN::Save( FILE* aFile ) const { // Creates header - if( fprintf( aFile, "%s %s %d", EESCHEMA_FILE_STAMP, - SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) < 0 - || fprintf( aFile, " date %s\n", TO_UTF8( DateAndTime() ) ) < 0 ) + if( fprintf( aFile, "%s %s %d\n", EESCHEMA_FILE_STAMP, + SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) < 0 ) return false; BOOST_FOREACH( const CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) @@ -961,7 +960,7 @@ bool SCH_SCREEN::BreakSegmentsOnJunctions() if( BreakSegment( junction->GetPosition() ) ) brokenSegments = true; } - else + else { SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast( item ); if( busEntry ) diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 0b2b40c336..9b801d452e 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -139,7 +139,7 @@ void MODULE::TransformGraphicShapesWithClearanceToPolygonSet( corner.y += GetPosition().y; aCornerBuffer.Append( corner ); } - aCornerBuffer.back().end_contour = true; + aCornerBuffer.CloseLastContour(); break; default: @@ -242,7 +242,7 @@ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon( aCornerBuffer.Append( corners[ii] ); } - aCornerBuffer.back().end_contour = true; + aCornerBuffer.CloseLastContour(); } @@ -875,7 +875,7 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer, aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) ); } - aCornerBuffer.back().end_contour = true; + aCornerBuffer.CloseLastContour(); angle = AddAngles( angle, 1800 ); // this is calculate hole 3 } @@ -900,7 +900,7 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer, aCornerBuffer.Append( CPolyPt( cpos.x, cpos.y ) ); } - aCornerBuffer.back().end_contour = true; + aCornerBuffer.CloseLastContour(); angle = AddAngles( angle, 1800 ); } } diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 65385ec9ee..4618255a91 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -90,8 +90,8 @@ ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) : m_PadConnection = aZone.m_PadConnection; m_ThermalReliefGap = aZone.m_ThermalReliefGap; m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge; - m_FilledPolysList = aZone.m_FilledPolysList; - m_FillSegmList = aZone.m_FillSegmList; + m_FilledPolysList.Append( aZone.m_FilledPolysList ); + m_FillSegmList = aZone.m_FillSegmList; // vector <> copy m_isKeepout = aZone.m_isKeepout; m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour; @@ -123,7 +123,7 @@ bool ZONE_CONTAINER::UnFill() bool change = ( m_FilledPolysList.GetCornersCount() > 0 ) || ( m_FillSegmList.size() > 0 ); - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); m_FillSegmList.clear(); m_IsFilled = false; @@ -740,7 +740,7 @@ void ZONE_CONTAINER::Move( const wxPoint& offset ) for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ ) { m_FilledPolysList.SetX( ic, m_FilledPolysList.GetX( ic ) + offset.x ); - m_FilledPolysList.SetY( ic, m_FilledPolysList.GetX( ic ) + offset.y ); + m_FilledPolysList.SetY( ic, m_FilledPolysList.GetY( ic ) + offset.y ); } for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ ) @@ -863,8 +863,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src ) m_Poly->SetHatchStyle( src->m_Poly->GetHatchStyle() ); m_Poly->SetHatchPitch( src->m_Poly->GetHatchPitch() ); m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector - m_FilledPolysList.clear(); - m_FilledPolysList = src->m_FilledPolysList; + m_FilledPolysList.RemoveAllContours(); + m_FilledPolysList.Append( src->m_FilledPolysList ); m_FillSegmList.clear(); m_FillSegmList = src->m_FillSegmList; } diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index fcdefe5898..45fcafbfea 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -498,7 +498,7 @@ public: */ void ClearFilledPolysList() { - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); } /** diff --git a/pcbnew/zone_filling_algorithm.cpp b/pcbnew/zone_filling_algorithm.cpp index a106f50df3..04da8e2fdc 100644 --- a/pcbnew/zone_filling_algorithm.cpp +++ b/pcbnew/zone_filling_algorithm.cpp @@ -58,7 +58,7 @@ bool ZONE_CONTAINER::BuildFilledSolidAreasPolygons( BOARD* aPcb, CPOLYGONS_LIST* aCornerBuffer ) { if( aCornerBuffer == NULL ) - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); /* convert outlines + holes to outlines without holes (adding extra segments if necessary) * m_Poly data is expected normalized, i.e. NormalizeAreaOutlines was used after building @@ -121,7 +121,7 @@ bool ZONE_CONTAINER::BuildFilledSolidAreasPolygons( BOARD* aPcb, CopyPolygonsFromFilledPolysListToKiPolygonList( polyset_zone_solid_areas ); polyset_zone_solid_areas -= margin; // put solid area in m_FilledPolysList: - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); CopyPolygonsFromKiPolygonListToFilledPolysList( polyset_zone_solid_areas ); } if ( m_FillMode ) // if fill mode uses segments, create them: diff --git a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp index ef67888701..26a6cb67c1 100644 --- a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp +++ b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp @@ -188,7 +188,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) // static to avoid unnecessary memory allocation when filling many zones. static CPOLYGONS_LIST cornerBufferPolysToSubstract; - cornerBufferPolysToSubstract.clear(); + cornerBufferPolysToSubstract.RemoveAllContours(); /* Use a dummy pad to calculate hole clerance when a pad is not on all copper layers * and this pad has a hole @@ -423,7 +423,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) } // put solid areas in m_FilledPolysList: - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); CopyPolygonsFromKiPolygonListToFilledPolysList( polyset_zone_solid_areas ); // Remove insulated islands: @@ -431,7 +431,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) TestForCopperIslandAndRemoveInsulatedIslands( aPcb ); // Now we remove all unused thermal stubs. - cornerBufferPolysToSubstract.clear(); + cornerBufferPolysToSubstract.RemoveAllContours(); // Test thermal stubs connections and add polygons to remove unconnected stubs. // (this is a refinement for thermal relief shapes) @@ -449,20 +449,20 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) polyset_zone_solid_areas -= polyset_holes; // put these areas in m_FilledPolysList - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); CopyPolygonsFromKiPolygonListToFilledPolysList( polyset_zone_solid_areas ); if( GetNet() > 0 ) TestForCopperIslandAndRemoveInsulatedIslands( aPcb ); } - cornerBufferPolysToSubstract.clear(); + cornerBufferPolysToSubstract.RemoveAllContours(); } void ZONE_CONTAINER::CopyPolygonsFromKiPolygonListToFilledPolysList( KI_POLYGON_SET& aKiPolyList ) { - m_FilledPolysList.clear(); + m_FilledPolysList.RemoveAllContours(); m_FilledPolysList.ImportFrom( aKiPolyList ); } diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index a50685233d..13c5d08cf9 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -25,6 +25,12 @@ CPolyLine::CPolyLine() m_utility = 0; } +CPolyLine::CPolyLine( const CPolyLine& aCPolyLine) +{ + Copy( &aCPolyLine ); + m_HatchLines = aCPolyLine.m_HatchLines; // vector <> copy +} + // destructor, removes display elements // @@ -517,11 +523,11 @@ void CPolyLine::RemoveAllContours( void ) /** * function RemoveAllContours - * removes all corners from the lists. - * Others params are not chnaged + * removes all corners from the list. + * Others params are not changed */ { - m_CornersList.clear(); + m_CornersList.RemoveAllContours(); } @@ -937,27 +943,25 @@ bool CPolyLine::TestPointInside( int px, int py ) } -// copy data from another poly, but don't draw it -// -void CPolyLine::Copy( CPolyLine* src ) +// copy data from another CPolyLine, but don't draw it +void CPolyLine::Copy( const CPolyLine* src ) { UnHatch(); + m_layer = src->m_layer; m_hatchStyle = src->m_hatchStyle; m_hatchPitch = src->m_hatchPitch; - // copy corners, using vector copy - m_CornersList = src->m_CornersList; + m_CornersList.RemoveAllContours(); + m_CornersList.Append( src->m_CornersList ); } -/*******************************************/ -bool CPolyLine::IsCutoutContour( int icont ) -/*******************************************/ - /* - * return true if the corner icont is inside the outline (i.e it is a hole) + * return true if the corner aCornerIdx is on a hole inside the main outline + * and false if it is on the main outline */ +bool CPolyLine::IsCutoutContour( int aCornerIdx ) { - int ncont = GetContour( icont ); + int ncont = GetContour( aCornerIdx ); if( ncont == 0 ) // the first contour is the main outline, not an hole return false; diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index d186f1ec43..a7ae63d131 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -117,8 +117,10 @@ public: // vector <> methods void reserve( int aSize ) { m_cornersList.reserve( aSize ); } - void clear() { m_cornersList.clear(); } - CPolyPt& back() { return m_cornersList.back(); } + + + void RemoveAllContours( void ) { m_cornersList.clear(); } + CPolyPt& GetLastCorner() { return m_cornersList.back(); } unsigned GetCornersCount() const { return m_cornersList.size(); } @@ -206,6 +208,7 @@ public: // constructors/destructor CPolyLine(); + CPolyLine( const CPolyLine& aCPolyLine); ~CPolyLine(); /** @@ -296,9 +299,14 @@ public: CRect GetBounds(); CRect GetCornerBounds(); CRect GetCornerBounds( int icont ); - void Copy( CPolyLine* src ); + void Copy( const CPolyLine* src ); bool TestPointInside( int x, int y ); - bool IsCutoutContour( int icont ); + + /** + * @return true if the corner aCornerIdx is on a hole inside the main outline + * and false if it is on the main outline + */ + bool IsCutoutContour( int aCornerIdx ); /** * Function AppendArc.