From 7f64899591c526dcc13638606e29e5dcc51c2328 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 13 Oct 2013 18:47:11 +0200 Subject: [PATCH] specctra_export.cpp: fix a bug in my export function to 3D viewer which generates bad shapes for holes generated by outlines inside the main board outlines. specctra_export.cpp: always approximate arcs in outlines by 36 segm for 360 degrees, even for arc angle which differs from 90 degrees. 90 degrees is the default when creating an arc, but the arc value can be edited and have any value between 0 and 360 degrees. Previously, 9 segments were used regardless the arc angle. --- 3d-viewer/3d_canvas.cpp | 14 +++++++------- 3d-viewer/3d_draw.cpp | 3 ++- pcbnew/specctra_export.cpp | 33 ++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index d48deecfb3..c2b40270cf 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -489,24 +489,24 @@ void EDA_3D_CANVAS::InitGL() m_ZTop = 10.0; glDisable( GL_CULL_FACE ); // show back faces - glEnable( GL_DEPTH_TEST ); // Enable z-buferring - + glEnable( GL_ALPHA_TEST ); glEnable( GL_LINE_SMOOTH ); + glEnable(GL_POLYGON_SMOOTH); glEnable( GL_COLOR_MATERIAL ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); - /* speedups */ + // speedups glEnable( GL_DITHER ); - glShadeModel( GL_SMOOTH ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); - glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); // can be GL_FASTEST + glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); - /* blend */ + // Initialize alpha blending function. glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - } + glShadeModel( GL_FLAT ); +} // set viewing projection diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index 7885f98af4..230bbc06e5 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -229,7 +229,8 @@ void EDA_3D_CANVAS::BuildBoard3DView() allLayerHoles, &msg ) ) { msg << wxT("\n\n") << - _("Unable to calculate the board outlines, will use the outlines boundary box"); + _("Unable to calculate the board outlines.\n" + "Therefore use the board boundary box."); wxMessageBox( msg ); } diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 67cd3c1944..ded903fa1f 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -882,6 +882,7 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER { TYPE_COLLECTOR items; unsigned prox; // a proximity BIU metric, not an accurate distance + const int STEPS = 36; // for a segmentation of an arc of 360 degrees // Get all the DRAWSEGMENTS and module graphics into 'items', // then keep only those on layer == EDGE_N. @@ -945,17 +946,19 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER // an arc with a series of short lines and put those // line segments into the !same! PATH. { - const int STEPS = 9; // in an arc of 90 degrees - wxPoint start = graphic->GetArcStart(); wxPoint center = graphic->GetCenter(); double angle = -graphic->GetAngle(); + int steps = STEPS * fabs(angle) /3600.0; + + if( steps == 0 ) + steps = 1; wxPoint pt; - for( int step = 1; step<=STEPS; ++step ) + for( int step = 1; step<=steps; ++step ) { - double rotation = ( angle * step ) / STEPS; + double rotation = ( angle * step ) / steps; pt = start; @@ -1053,12 +1056,14 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER // an arc with a series of short lines and put those // line segments into the !same! PATH. { - const int STEPS = 9; // in an arc of 90 degrees - wxPoint start = graphic->GetArcStart(); wxPoint end = graphic->GetArcEnd(); wxPoint center = graphic->GetCenter(); double angle = -graphic->GetAngle(); + int steps = STEPS * fabs(angle) /3600.0; + + if( steps == 0 ) + steps = 1; if( !close_enough( prevPt, start, prox ) ) { @@ -1070,9 +1075,9 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER wxPoint nextPt; - for( int step = 1; step<=STEPS; ++step ) + for( int step = 1; step<=steps; ++step ) { - double rotation = ( angle * step ) / STEPS; + double rotation = ( angle * step ) / steps; nextPt = start; @@ -1169,12 +1174,14 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER // an arc with a series of short lines and put those // line segments into the !same! PATH. { - const int STEPS = 9; // in an arc of 90 degrees - wxPoint start = graphic->GetArcStart(); wxPoint end = graphic->GetArcEnd(); wxPoint center = graphic->GetCenter(); double angle = -graphic->GetAngle(); + int steps = STEPS * fabs(angle) /3600.0; + + if( steps == 0 ) + steps = 1; if( !close_enough( prevPt, start, prox ) ) { @@ -1186,9 +1193,9 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER wxPoint nextPt; - for( int step = 1; step<=STEPS; ++step ) + for( int step = 1; step<=steps; ++step ) { - double rotation = ( angle * step ) / STEPS; + double rotation = ( angle * step ) / steps; nextPt = start; @@ -1300,7 +1307,7 @@ bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard, KEEPOUT& keepout = *i; PATH* poly_hole = (PATH*)keepout.shape; POINTS& plist = poly_hole->GetPoints(); - for( unsigned ii = 0; ii < plist.size(); ii+=2 ) + for( unsigned ii = 0; ii < plist.size(); ii++ ) { corner.x = plist[ii].x * specctra2UIfactor; corner.y = - plist[ii].y * specctra2UIfactor;