Commit 115cb2d6 authored by jean-pierre charras's avatar jean-pierre charras

Try to fix Bug #1431765 (Pcbnew crashes in GAL when entering 3d display when a...

Try to fix Bug #1431765 (Pcbnew crashes in GAL when entering 3d display when a board outline is not closed)
This change modify the way warning messages are displayed: now the are displayed outside a paint event.
parent 1d2e2e55
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#include <3d_struct.h> #include <3d_struct.h>
#include <class_module.h> #include <class_module.h>
class BOARD_DESIGN_SETTINGS; class BOARD_DESIGN_SETTINGS;
class EDA_3D_FRAME; class EDA_3D_FRAME;
class CPOLYGONS_LIST; class CPOLYGONS_LIST;
...@@ -132,9 +132,11 @@ public: ...@@ -132,9 +132,11 @@ public:
/** /**
* Function CreateDrawGL_List * Function CreateDrawGL_List
* Prepares the parameters of the OpenGL draw list * Prepares the parameters of the OpenGL draw list
* creates the OpenGL draw list items (board, grid ... * creates the OpenGL draw list items (board, grid ...)
* @param aErrorMessages = a wxString which will filled with error messages,
* if any
*/ */
void CreateDrawGL_List(); void CreateDrawGL_List( wxString* aErrorMessages );
void InitGL(); void InitGL();
void SetLights(); void SetLights();
...@@ -209,15 +211,17 @@ private: ...@@ -209,15 +211,17 @@ private:
* Called by CreateDrawGL_List() * Called by CreateDrawGL_List()
* Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers. * Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers.
* 3D footprint shapes, tech layers and aux layers are not on this list * 3D footprint shapes, tech layers and aux layers are not on this list
* Fills aErrorMessages with error messages created by some calculation function
*/ */
void BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList); void BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList, wxString* aErrorMessages );
/** /**
* Function BuildTechLayers3DView * Function BuildTechLayers3DView
* Called by CreateDrawGL_List() * Called by CreateDrawGL_List()
* Populates the OpenGL GL_ID_TECH_LAYERS draw list with items on tech layers * Populates the OpenGL GL_ID_TECH_LAYERS draw list with items on tech layers
* Add error messages in aErrorMessages, if any
*/ */
void BuildTechLayers3DView(); void BuildTechLayers3DView( wxString* aErrorMessages );
/** /**
* Function BuildShadowList * Function BuildShadowList
...@@ -301,7 +305,7 @@ private: ...@@ -301,7 +305,7 @@ private:
std::vector<S3D_MODEL_PARSER *>& model_parsers_list, std::vector<S3D_MODEL_PARSER *>& model_parsers_list,
std::vector<wxString>& model_filename_list ); std::vector<wxString>& model_filename_list );
void GenerateFakeShadowsTextures(); void GenerateFakeShadowsTextures( wxString* aErrorMessages );
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
......
...@@ -110,7 +110,7 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, ...@@ -110,7 +110,7 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture,
CIMAGE imgDepthBufferAux( aTexture_size, aTexture_size ); CIMAGE imgDepthBufferAux( aTexture_size, aTexture_size );
imgDepthBuffer.setPixelsFromNormalizedFloat( depthbufferFloat ); imgDepthBuffer.setPixelsFromNormalizedFloat( depthbufferFloat );
free( depthbufferFloat ); free( depthbufferFloat );
wxString filename; wxString filename;
...@@ -160,7 +160,7 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, ...@@ -160,7 +160,7 @@ void EDA_3D_CANVAS::Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture,
#define SHADOW_BOARD_SCALE 1.5f #define SHADOW_BOARD_SCALE 1.5f
void EDA_3D_CANVAS::GenerateFakeShadowsTextures() void EDA_3D_CANVAS::GenerateFakeShadowsTextures( wxString* aErrorMessages )
{ {
if( m_shadow_init == true ) if( m_shadow_init == true )
{ {
...@@ -168,7 +168,7 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures() ...@@ -168,7 +168,7 @@ void EDA_3D_CANVAS::GenerateFakeShadowsTextures()
} }
// Init info 3d parameters and create gl lists: // Init info 3d parameters and create gl lists:
CreateDrawGL_List(); CreateDrawGL_List( aErrorMessages );
m_shadow_init = true; m_shadow_init = true;
...@@ -225,6 +225,8 @@ void EDA_3D_CANVAS::Redraw() ...@@ -225,6 +225,8 @@ void EDA_3D_CANVAS::Redraw()
if( !IsShown() ) if( !IsShown() )
return; return;
wxString errorMessages;
SetCurrent( *m_glRC ); SetCurrent( *m_glRC );
// Set the OpenGL viewport according to the client size of this canvas. // Set the OpenGL viewport according to the client size of this canvas.
...@@ -240,7 +242,7 @@ void EDA_3D_CANVAS::Redraw() ...@@ -240,7 +242,7 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_MODULE ) && isRealisticMode() && if( isEnabled( FL_MODULE ) && isRealisticMode() &&
isEnabled( FL_RENDER_SHADOWS ) ) isEnabled( FL_RENDER_SHADOWS ) )
{ {
GenerateFakeShadowsTextures(); GenerateFakeShadowsTextures( &errorMessages );
} }
// *MUST* be called *after* SetCurrent( ): // *MUST* be called *after* SetCurrent( ):
...@@ -251,9 +253,9 @@ void EDA_3D_CANVAS::Redraw() ...@@ -251,9 +253,9 @@ void EDA_3D_CANVAS::Redraw()
glClearStencil( 0 ); glClearStencil( 0 );
glClearDepth( 1.0 ); glClearDepth( 1.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
glShadeModel( GL_SMOOTH ); glShadeModel( GL_SMOOTH );
// Draw background // Draw background
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
glLoadIdentity(); glLoadIdentity();
...@@ -336,7 +338,7 @@ void EDA_3D_CANVAS::Redraw() ...@@ -336,7 +338,7 @@ void EDA_3D_CANVAS::Redraw()
if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] )
CreateDrawGL_List(); CreateDrawGL_List( &errorMessages );
if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] ) if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] )
glCallList( m_glLists[GL_ID_AXIS] ); glCallList( m_glLists[GL_ID_AXIS] );
...@@ -352,7 +354,7 @@ void EDA_3D_CANVAS::Redraw() ...@@ -352,7 +354,7 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_MODULE ) ) if( isEnabled( FL_MODULE ) )
{ {
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
CreateDrawGL_List(); CreateDrawGL_List( &errorMessages );
} }
glEnable( GL_BLEND ); glEnable( GL_BLEND );
...@@ -402,7 +404,7 @@ void EDA_3D_CANVAS::Redraw() ...@@ -402,7 +404,7 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_COMMENTS ) || isEnabled( FL_COMMENTS ) ) if( isEnabled( FL_COMMENTS ) || isEnabled( FL_COMMENTS ) )
{ {
if( ! m_glLists[GL_ID_AUX_LAYERS] ) if( ! m_glLists[GL_ID_AUX_LAYERS] )
CreateDrawGL_List(); CreateDrawGL_List( &errorMessages );
glCallList( m_glLists[GL_ID_AUX_LAYERS] ); glCallList( m_glLists[GL_ID_AUX_LAYERS] );
} }
...@@ -450,7 +452,7 @@ void EDA_3D_CANVAS::Redraw() ...@@ -450,7 +452,7 @@ void EDA_3D_CANVAS::Redraw()
if( isEnabled( FL_MODULE ) ) if( isEnabled( FL_MODULE ) )
{ {
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
CreateDrawGL_List(); CreateDrawGL_List( &errorMessages );
glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ); glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] );
} }
...@@ -492,6 +494,9 @@ void EDA_3D_CANVAS::Redraw() ...@@ -492,6 +494,9 @@ void EDA_3D_CANVAS::Redraw()
} }
SwapBuffers(); SwapBuffers();
if( !errorMessages.IsEmpty() )
wxLogMessage( errorMessages );
} }
...@@ -571,7 +576,8 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint ...@@ -571,7 +576,8 @@ void EDA_3D_CANVAS::BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint
} }
void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList ) void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
wxString* aErrorMessages )
{ {
BOARD* pcb = GetBoard(); BOARD* pcb = GetBoard();
...@@ -609,10 +615,12 @@ void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList ) ...@@ -609,10 +615,12 @@ void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList )
if( !pcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) ) if( !pcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) )
{ {
msg << wxT("\n\n") << if( aErrorMessages )
_("Unable to calculate the board outlines.\n" {
"Therefore use the board boundary box."); *aErrorMessages << msg << wxT("\n") <<
wxMessageBox( msg ); _("Unable to calculate the board outlines.\n"
"Therefore use the board boundary box.") << wxT("\n\n");
}
} }
CPOLYGONS_LIST bufferZonesPolys; CPOLYGONS_LIST bufferZonesPolys;
...@@ -878,7 +886,7 @@ void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList ) ...@@ -878,7 +886,7 @@ void EDA_3D_CANVAS::BuildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList )
} }
void EDA_3D_CANVAS::BuildTechLayers3DView() void EDA_3D_CANVAS::BuildTechLayers3DView( wxString* aErrorMessages )
{ {
BOARD* pcb = GetBoard(); BOARD* pcb = GetBoard();
bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ); bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES );
...@@ -899,15 +907,23 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() ...@@ -899,15 +907,23 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
allLayerHoles.reserve( 20000 ); allLayerHoles.reserve( 20000 );
CPOLYGONS_LIST bufferPcbOutlines; // stores the board main outlines CPOLYGONS_LIST bufferPcbOutlines; // stores the board main outlines
// Build a polygon from edge cut items // Build a polygon from edge cut items
wxString msg; wxString msg;
if( !pcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) ) if( !pcb->GetBoardPolygonOutlines( bufferPcbOutlines, allLayerHoles, &msg ) )
{ {
msg << wxT("\n\n") << #if 0
_("Unable to calculate the board outlines.\n" // Usually this message is already shown when the copper layers are built
"Therefore use the board boundary box."); // So do not show it twice.
wxMessageBox( msg ); // TODO: display it only if when copper layers are not built
if( aErrorMessages )
{
*aErrorMessages << msg << wxT("\n") <<
_("Unable to calculate the board outlines.\n"
"Therefore use the board boundary box.") << wxT("\n\n");
}
#endif
} }
int thickness = GetPrm3DVisu().GetCopperThicknessBIU(); int thickness = GetPrm3DVisu().GetCopperThicknessBIU();
...@@ -1194,7 +1210,7 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers() ...@@ -1194,7 +1210,7 @@ void EDA_3D_CANVAS::BuildBoard3DAuxLayers()
} }
} }
void EDA_3D_CANVAS::CreateDrawGL_List() void EDA_3D_CANVAS::CreateDrawGL_List( wxString* aErrorMessages)
{ {
BOARD* pcb = GetBoard(); BOARD* pcb = GetBoard();
...@@ -1232,7 +1248,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() ...@@ -1232,7 +1248,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
{ {
m_glLists[GL_ID_BOARD] = glGenLists( 1 ); m_glLists[GL_ID_BOARD] = glGenLists( 1 );
m_glLists[GL_ID_BODY] = glGenLists( 1 ); m_glLists[GL_ID_BODY] = glGenLists( 1 );
BuildBoard3DView(m_glLists[GL_ID_BOARD], m_glLists[GL_ID_BODY]); BuildBoard3DView(m_glLists[GL_ID_BOARD], m_glLists[GL_ID_BODY], aErrorMessages );
CheckGLError( __FILE__, __LINE__ ); CheckGLError( __FILE__, __LINE__ );
} }
...@@ -1240,7 +1256,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() ...@@ -1240,7 +1256,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
{ {
m_glLists[GL_ID_TECH_LAYERS] = glGenLists( 1 ); m_glLists[GL_ID_TECH_LAYERS] = glGenLists( 1 );
glNewList( m_glLists[GL_ID_TECH_LAYERS], GL_COMPILE ); glNewList( m_glLists[GL_ID_TECH_LAYERS], GL_COMPILE );
BuildTechLayers3DView(); BuildTechLayers3DView( aErrorMessages );
glEndList(); glEndList();
CheckGLError( __FILE__, __LINE__ ); CheckGLError( __FILE__, __LINE__ );
} }
......
...@@ -626,9 +626,10 @@ void EDA_3D_FRAME::NewDisplay( int aGlList ) ...@@ -626,9 +626,10 @@ void EDA_3D_FRAME::NewDisplay( int aGlList )
m_reloadRequest = false; m_reloadRequest = false;
m_canvas->ClearLists( aGlList ); m_canvas->ClearLists( aGlList );
m_canvas->CreateDrawGL_List();
// Rebuild the 3D board and refresh the view:
m_canvas->Refresh( true ); m_canvas->Refresh( true );
m_canvas->DisplayStatus(); m_canvas->DisplayStatus();
} }
......
...@@ -1336,13 +1336,18 @@ bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard, ...@@ -1336,13 +1336,18 @@ bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard,
// Creates a valid polygon outline is not possible. // Creates a valid polygon outline is not possible.
// So uses the board edge cuts bounding box to create a // So uses the board edge cuts bounding box to create a
// rectangular outline // rectangular outline
// (when no edge cuts items, fillBOUNDARY biuld n outline // (when no edge cuts items, fillBOUNDARY build a contour
// from global bounding box // from global bounding box
success = false; success = false;
if( aErrorText ) if( aErrorText )
*aErrorText = ioe.errorText; *aErrorText = ioe.errorText;
EDA_RECT bbbox = aBoard->ComputeBoundingBox( true ); EDA_RECT bbbox = aBoard->ComputeBoundingBox( true );
// Ensure non null area. If happen, gives a minimal size.
if( ( bbbox.GetWidth() ) == 0 || ( bbbox.GetHeight() == 0 ) )
bbbox.Inflate( Millimeter2iu( 1.0 ) );
corner.x = bbbox.GetOrigin().x; corner.x = bbbox.GetOrigin().x;
corner.y = bbbox.GetOrigin().y; corner.y = bbbox.GetOrigin().y;
aOutlines.Append( corner ); aOutlines.Append( corner );
......
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