From ab58b6784246fef3af8c31e4ac4653ef13717656 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 12 Aug 2020 06:16:57 -0700 Subject: [PATCH] Adding triangulation viewing to AC This adds a helper routine to visualize the quality of our triangulation. It also renames an excessively long variable name for the arc editor --- common/advanced_config.cpp | 25 +++++++++++++++++-------- common/gal/opengl/opengl_gal.cpp | 27 +++++++++++++++++++++++++++ include/advanced_config.h | 8 ++++++-- pcbnew/tools/point_editor.cpp | 2 +- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index 5fd2b43cb4..cde700ae2d 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -108,6 +108,11 @@ static const wxChar DrawArcAccuracy[] = wxT( "DrawArcAccuracy" ); */ static const wxChar DrawArcCenterStartEndMaxAngle[] = wxT( "DrawArcCenterStartEndMaxAngle" ); +/** + * When true, GAL will stroke the triangulations (only used in OpenGL) with a visible color + */ +static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" ); + } // namespace KEYS @@ -185,11 +190,12 @@ ADVANCED_CFG::ADVANCED_CFG() // Init defaults - this is done in case the config doesn't exist, // then the values will remain as set here. - m_realTimeConnectivity = true; - m_coroutineStackSize = AC_STACK::default_stack; - m_ShowRouterDebugGraphics = false; - m_drawArcAccuracy = 10.0; - m_drawArcCenterStartEndMaxAngle = 50.0; + m_realTimeConnectivity = true; + m_coroutineStackSize = AC_STACK::default_stack; + m_ShowRouterDebugGraphics = false; + m_drawArcAccuracy = 10.0; + m_drawArcCenterMaxAngle = 50.0; + m_DrawTriangulationOutlines = false; loadFromConfigFile(); } @@ -239,11 +245,14 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave, &m_CompactSave, false ) ); - configParams.push_back( new PARAM_CFG_DOUBLE( - true, AC_KEYS::DrawArcAccuracy, &m_drawArcAccuracy, 10.0, 0.0, 100000.0 ) ); + configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcAccuracy, + &m_drawArcAccuracy, 10.0, 0.0, 100000.0 ) ); configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcCenterStartEndMaxAngle, - &m_drawArcCenterStartEndMaxAngle, 50.0, 0.0, 100000.0 ) ); + &m_drawArcCenterMaxAngle, 50.0, 0.0, 100000.0 ) ); + + configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation, + &m_DrawTriangulationOutlines, false ) ); wxConfigLoadSetups( &aCfg, configParams ); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index ed27cac916..ccd4349727 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -1043,6 +1044,32 @@ void OPENGL_GAL::drawTriangulatedPolyset( const SHAPE_POLY_SET& aPolySet ) } } } + + if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines ) + { + auto oldStrokeColor = strokeColor; + double oldLayerDepth = layerDepth; + + SetLayerDepth( layerDepth - 1 ); + SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) ); + + for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j ) + { + auto triPoly = aPolySet.TriangulatedPolygon( j ); + + for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ ) + { + VECTOR2I a, b, c; + triPoly->GetTriangle( i, a, b, c ); + DrawLine( a, b ); + DrawLine( b, c ); + DrawLine( c, a ); + } + } + + SetStrokeColor( oldStrokeColor ); + SetLayerDepth( oldLayerDepth ); + } } diff --git a/include/advanced_config.h b/include/advanced_config.h index df5c58f7dc..ffe81fb04e 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -77,10 +77,10 @@ public: /** * For drawsegments - arcs. - * When drawing an arc, the angle ( center - start ) - ( start - end ) + * When drawing an arc, the angle ( center - start ) - ( start - end ) * can be limited to avoid extremely high radii. */ - double m_drawArcCenterStartEndMaxAngle; + double m_drawArcCenterMaxAngle; /** * Extra fill clearance for zone fills @@ -108,6 +108,10 @@ public: */ bool m_CompactSave; + /** + * When true, strokes the triangulations with visible color + */ + bool m_DrawTriangulationOutlines; private: ADVANCED_CFG(); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 6cb385bbe7..0d54d86c49 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -732,7 +732,7 @@ void POINT_EDITOR::updateItem() const // This is just to limit the radius, so nothing overflows later when drawing. if( abs( v2.y / ( R - v2.x ) ) - > ADVANCED_CFG::GetCfg().m_drawArcCenterStartEndMaxAngle ) + > ADVANCED_CFG::GetCfg().m_drawArcCenterMaxAngle ) { arcValid = false; }