Browse Source

Ensure triangulation follows moving zone

Dragging filled zones in OpenGL was extremely slow due to the
invalidated triangulation cache.  Moving the zone should also move the
triangles and keep the cache valid.
pull/16/head
Seth Hillbrand 5 years ago
parent
commit
08c61e6788
  1. 2
      3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp
  2. 9
      libs/kimath/include/geometry/shape_poly_set.h
  3. 31
      libs/kimath/src/geometry/shape_poly_set.cpp
  4. 13
      pcbnew/class_zone.cpp

2
3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp

@ -875,7 +875,7 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE_CONTAINER* aZoneC
PCB_LAYER_ID aLayerId )
{
// Copy the polys list because we have to simplify it
SHAPE_POLY_SET polyList = SHAPE_POLY_SET( aZoneContainer->GetFilledPolysList(), true );
SHAPE_POLY_SET polyList = SHAPE_POLY_SET( aZoneContainer->GetFilledPolysList() );
// This convert the poly in outline and holes
Convert_shape_line_polygon_to_triangles( polyList, *aDstContainer, m_biuTo3Dunits,

9
libs/kimath/include/geometry/shape_poly_set.h

@ -119,6 +119,12 @@ class SHAPE_POLY_SET : public SHAPE
return m_vertices.size();
}
void Move( const VECTOR2I& aVec )
{
for( auto& vertex : m_vertices )
vertex += aVec;
}
private:
std::deque<TRI> m_triangles;
@ -448,9 +454,8 @@ class SHAPE_POLY_SET : public SHAPE
* Copy constructor SHAPE_POLY_SET
* Performs a deep copy of \p aOther into \p this.
* @param aOther is the SHAPE_POLY_SET object that will be copied.
* @param aDeepCopy if true, make new copies of the triangulated unique_ptr vector
*/
SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy = false );
SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther );
~SHAPE_POLY_SET();

31
libs/kimath/src/geometry/shape_poly_set.cpp

@ -67,8 +67,8 @@ SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_LINE_CHAIN& aOutline ) :
}
SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy ) :
SHAPE( SH_POLY_SET ), m_polys( aOther.m_polys )
SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ) :
SHAPE( aOther ), m_polys( aOther.m_polys )
{
if( aOther.IsTriangulationUpToDate() )
{
@ -79,6 +79,12 @@ SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy ) :
m_hash = aOther.GetHash();
m_triangulationValid = true;
}
else
{
m_triangulationValid = false;
m_hash = MD5_HASH();
m_triangulatedPolys.clear();
}
}
@ -1519,6 +1525,11 @@ void SHAPE_POLY_SET::Move( const VECTOR2I& aVector )
for( SHAPE_LINE_CHAIN& path : poly )
path.Move( aVector );
}
for( auto& tri : m_triangulatedPolys )
tri->Move( aVector );
m_hash = checksum();
}
@ -1873,11 +1884,19 @@ SHAPE_POLY_SET &SHAPE_POLY_SET::operator=( const SHAPE_POLY_SET& aOther )
{
static_cast<SHAPE&>(*this) = aOther;
m_polys = aOther.m_polys;
// reset poly cache:
m_hash = MD5_HASH{};
m_triangulationValid = false;
m_triangulatedPolys.clear();
m_triangulationValid = false;
if( aOther.IsTriangulationUpToDate() )
{
for( unsigned i = 0; i < aOther.TriangulatedPolyCount(); i++ )
m_triangulatedPolys.push_back(
std::make_unique<TRIANGULATED_POLYGON>( *aOther.TriangulatedPolygon( i ) ) );
m_hash = aOther.GetHash();
m_triangulationValid = true;
}
return *this;
}

13
pcbnew/class_zone.cpp

@ -107,10 +107,11 @@ ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther )
SetHatchStyle( aOther.GetHatchStyle() );
SetHatchPitch( aOther.GetHatchPitch() );
m_HatchLines = aOther.m_HatchLines; // copy vector <SEG>
m_FilledPolysList.RemoveAllContours();
m_FilledPolysList.Append( aOther.m_FilledPolysList );
m_FillSegmList.clear();
m_FillSegmList = aOther.m_FillSegmList;
m_FilledPolysList = aOther.m_FilledPolysList;
m_RawPolysList = aOther.m_RawPolysList;
m_filledPolysHash = aOther.m_filledPolysHash;
m_FillSegmList = aOther.m_FillSegmList; // vector <> copy
m_HatchFillTypeThickness = aOther.m_HatchFillTypeThickness;
m_HatchFillTypeGap = aOther.m_HatchFillTypeGap;
@ -158,7 +159,9 @@ void ZONE_CONTAINER::initDataFromSrcInCopyCtor( const ZONE_CONTAINER& aZone )
m_PadConnection = aZone.m_PadConnection;
m_ThermalReliefGap = aZone.m_ThermalReliefGap;
m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge;
m_FilledPolysList.Append( aZone.m_FilledPolysList );
m_FilledPolysList = aZone.m_FilledPolysList;
m_RawPolysList = aZone.m_RawPolysList;
m_filledPolysHash = aZone.m_filledPolysHash;
m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;

Loading…
Cancel
Save