Commit bbbb84e6 authored by jean-pierre charras's avatar jean-pierre charras

Fix a few minor coverity warnings.

Fix minor 3D viewer issues (includling change number of segments and its optimization to draw pad holes.)
Fix Bug #1439132 (track and via list on toolbar not always refresh after loading a board).
Remove useless tool in Modedit.
parent 589dd442
...@@ -646,14 +646,14 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList, ...@@ -646,14 +646,14 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ); bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES );
// Number of segments to convert a circle to polygon // Number of segments to convert a circle to polygon
// Boost polygon (at least v 1.54, v1.55 and previous) in very rare cases crashes // Boost polygon (at least v1.57 and previous) in very rare cases crashes
// when using 16 segments to approximate a circle. // when using 16 segments to approximate a circle.
// So using 18 segments is a workaround to try to avoid these crashes // So using 18 segments is a workaround to try to avoid these crashes
// ( We already used this trick in plot_board_layers.cpp, // ( We already used this trick in plot_board_layers.cpp,
// see PlotSolderMaskLayer() ) // see PlotSolderMaskLayer() )
const int segcountforcircle = 18; const int segcountforcircle = 18;
double correctionFactor = 1.0 / cos( M_PI / (segcountforcircle * 2.0) ); double correctionFactor = 1.0 / cos( M_PI / (segcountforcircle * 2.0) );
const int segcountLowQuality = 8; // segments to draw a circle with low quality const int segcountLowQuality = 12; // segments to draw a circle with low quality
// to reduce time calculations // to reduce time calculations
// for holes and items which do not need // for holes and items which do not need
// a fine representation // a fine representation
...@@ -767,13 +767,28 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList, ...@@ -767,13 +767,28 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
for( ; pad; pad = pad->Next() ) for( ; pad; pad = pad->Next() )
{ {
// Calculate a factor to apply to segcount (bigger pad size -> more segments) // Calculate a factor to apply to segcount for large holes ( > 1 mm)
wxSize padSize = pad->GetSize(); // (bigger pad drill size -> more segments) because holes in pads can have
int maxPadSize = glm::max( padSize.x, padSize.y ); // very different sizes and optimizing this segcount gives a better look
float segFactor = (float)maxPadSize / (float)Millimeter2iu( 0.6 ); // Mainly mounting holes have a size bigger thon 1 mm
wxSize padHole = pad->GetDrillSize();
pad->BuildPadDrillShapePolygon( allLayerHoles, 0, if( ! padHole.x ) // Not drilled pad like SMD pad
(int)(segcountLowQuality * segFactor) ); continue;
// we use the hole diameter to calculate the seg count.
// for round holes, padHole.x == padHole.y
// for oblong holes, the diameter is the smaller of (padHole.x, padHole.y)
int diam = std::min( padHole.x, padHole.y );
double segFactor = (double)diam / Millimeter2iu( 1.0 );
int segcount = (int)(segcountLowQuality * segFactor);
// Clamp segcount between segcountLowQuality and 48.
// 48 segm for a circle is a very good approx.
segcount = Clamp( segcountLowQuality, segcount, 48 );
pad->BuildPadDrillShapePolygon( allLayerHoles, 0, segcount );
} }
} }
} }
......
...@@ -256,12 +256,15 @@ int ParseVertex( FILE* File, glm::vec3& dst_vertex ) ...@@ -256,12 +256,15 @@ int ParseVertex( FILE* File, glm::vec3& dst_vertex )
} }
int ParseFloat( FILE* File, float* dst_float ) bool ParseFloat( FILE* aFile, float *aDstFloat, float aDefaultValue )
{ {
float value; float value;
int ret = fscanf( File, "%e", &value ); int ret = fscanf( aFile, "%e", &value );
*dst_float = value; if( ret == 1 )
*aDstFloat = value;
else
*aDstFloat = aDefaultValue;
return ret; return ret == 1;
} }
...@@ -83,11 +83,12 @@ int ParseVertex( FILE* File, glm::vec3 &dst_vertex ); ...@@ -83,11 +83,12 @@ int ParseVertex( FILE* File, glm::vec3 &dst_vertex );
/** /**
* Function ParseFloat * Function ParseFloat
* parse a float value * parse a float value
* @param File file to read from * @param aFile file to read from
* @param dst_float destination float * @param aDstFloat destination float
* @return int - Return the number of floats readed (0 or 1) * @param aDefaultValue = the default value, when the actual value cannot be read
* @return bool - Return true if the float was read without error
*/ */
int ParseFloat( FILE* File, float *dst_float ); bool ParseFloat( FILE* aFile, float *aDstFloat, float aDefaultValue );
/** /**
* Function GetNextTag * Function GetNextTag
......
...@@ -1283,7 +1283,7 @@ int VRML2_MODEL_PARSER::read_Material() ...@@ -1283,7 +1283,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "ambientIntensity" ) == 0 ) else if( strcmp( text, "ambientIntensity" ) == 0 )
{ {
float ambientIntensity; float ambientIntensity;
ParseFloat( m_file, &ambientIntensity ); ParseFloat( m_file, &ambientIntensity, 0.8 );
if( m_Master->m_use_modelfile_ambientIntensity == true ) if( m_Master->m_use_modelfile_ambientIntensity == true )
{ {
...@@ -1294,7 +1294,7 @@ int VRML2_MODEL_PARSER::read_Material() ...@@ -1294,7 +1294,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "transparency" ) == 0 ) else if( strcmp( text, "transparency" ) == 0 )
{ {
float transparency; float transparency;
ParseFloat( m_file, &transparency ); ParseFloat( m_file, &transparency, 0.0 );
if( m_Master->m_use_modelfile_transparency == true ) if( m_Master->m_use_modelfile_transparency == true )
{ {
...@@ -1304,7 +1304,7 @@ int VRML2_MODEL_PARSER::read_Material() ...@@ -1304,7 +1304,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "shininess" ) == 0 ) else if( strcmp( text, "shininess" ) == 0 )
{ {
float shininess; float shininess;
ParseFloat( m_file, &shininess ); ParseFloat( m_file, &shininess, 1.0 );
// VRML value is normalized and openGL expects a value 0 - 128 // VRML value is normalized and openGL expects a value 0 - 128
if( m_Master->m_use_modelfile_shininess == true ) if( m_Master->m_use_modelfile_shininess == true )
......
...@@ -455,7 +455,12 @@ void PDF_PLOTTER::closePdfStream() ...@@ -455,7 +455,12 @@ void PDF_PLOTTER::closePdfStream()
wxASSERT( workFile ); wxASSERT( workFile );
long stream_len = ftell( workFile ); long stream_len = ftell( workFile );
wxASSERT( stream_len >= 0 );
if( stream_len < 0 )
{
wxASSERT( false );
return;
}
// Rewind the file, read in the page stream and DEFLATE it // Rewind the file, read in the page stream and DEFLATE it
fseek( workFile, 0, SEEK_SET ); fseek( workFile, 0, SEEK_SET );
...@@ -475,10 +480,10 @@ void PDF_PLOTTER::closePdfStream() ...@@ -475,10 +480,10 @@ void PDF_PLOTTER::closePdfStream()
{ {
/* Somewhat standard parameters to compress in DEFLATE. The PDF spec is /* Somewhat standard parameters to compress in DEFLATE. The PDF spec is
misleading, it says it wants a DEFLATE stream but it really want a ZLIB * misleading, it says it wants a DEFLATE stream but it really want a ZLIB
stream! (a DEFLATE stream would be generated with -15 instead of 15) * stream! (a DEFLATE stream would be generated with -15 instead of 15)
rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15, * rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15,
8, Z_DEFAULT_STRATEGY ); * 8, Z_DEFAULT_STRATEGY );
*/ */
wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB ); wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
......
...@@ -170,6 +170,7 @@ TRIANGULATION::TRIANGULATION() ...@@ -170,6 +170,7 @@ TRIANGULATION::TRIANGULATION()
TRIANGULATION::TRIANGULATION( const TRIANGULATION& aTriangulation ) TRIANGULATION::TRIANGULATION( const TRIANGULATION& aTriangulation )
{ {
m_helper = 0; // make coverity and static analysers quiet.
// Triangulation: Copy constructor not present // Triangulation: Copy constructor not present
assert( false ); assert( false );
} }
......
...@@ -156,7 +156,8 @@ void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent ) ...@@ -156,7 +156,8 @@ void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent )
// frame. Therefore this dialog as a modal frame parent, MUST be run under // frame. Therefore this dialog as a modal frame parent, MUST be run under
// quasimodal mode for the quasimodal frame support to work. So don't use // quasimodal mode for the quasimodal frame support to work. So don't use
// the QUASIMODAL macros here. // the QUASIMODAL macros here.
dlg->ShowQuasiModal(); int ret = dlg->ShowQuasiModal();
(void) ret; // not used. Make coverity and static analysers quiet.
m_canvas->SetIgnoreMouseEvents( false ); m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
......
...@@ -196,6 +196,9 @@ DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::DataViewModel( LIB_PART& aPart ) : ...@@ -196,6 +196,9 @@ DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::DataViewModel( LIB_PART& aPart ) :
m_GroupingColumn( 1 ), m_GroupingColumn( 1 ),
m_UnitCount( m_Part.GetUnitCount() ) m_UnitCount( m_Part.GetUnitCount() )
{ {
#ifdef REASSOCIATE_HACK
m_Widget = NULL;
#endif
aPart.GetPins( m_Backing ); aPart.GetPins( m_Backing );
/// @todo C++11 /// @todo C++11
for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i ) for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i )
......
...@@ -420,10 +420,13 @@ void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent ) ...@@ -420,10 +420,13 @@ void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent )
// Make the item temporarily visible just in case it's hide flag is set. This // Make the item temporarily visible just in case it's hide flag is set. This
// has no effect on objects that don't support hiding. If this is a close find // has no effect on objects that don't support hiding. If this is a close find
// dialog event, clear the temporary visibility flag. // dialog event, clear the temporary visibility flag.
if( item )
{
if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
item->SetForceVisible( false ); item->SetForceVisible( false );
else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() ) else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() )
item->SetForceVisible( true ); item->SetForceVisible( true );
}
if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() ) if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() )
{ {
......
...@@ -360,7 +360,7 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset, ...@@ -360,7 +360,7 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
EDA_TEXT::Draw( clipbox, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR ); EDA_TEXT::Draw( clipbox, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR );
EXCHG( linewidth, m_Thickness ); // set initial value EXCHG( linewidth, m_Thickness ); // set initial value
if( m_isDangling ) if( m_isDangling && panel)
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color ); DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
// Enable these line to draw the bounding box (debug tests purposes only) // Enable these line to draw the bounding box (debug tests purposes only)
...@@ -1282,7 +1282,7 @@ void SCH_GLOBALLABEL::Draw( EDA_DRAW_PANEL* panel, ...@@ -1282,7 +1282,7 @@ void SCH_GLOBALLABEL::Draw( EDA_DRAW_PANEL* panel,
CreateGraphicShape( Poly, m_Pos + aOffset ); CreateGraphicShape( Poly, m_Pos + aOffset );
GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color ); GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
if( m_isDangling ) if( m_isDangling && panel )
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color ); DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
// Enable these line to draw the bounding box (debug tests purposes only) // Enable these line to draw the bounding box (debug tests purposes only)
...@@ -1614,7 +1614,7 @@ void SCH_HIERLABEL::Draw( EDA_DRAW_PANEL* panel, ...@@ -1614,7 +1614,7 @@ void SCH_HIERLABEL::Draw( EDA_DRAW_PANEL* panel,
CreateGraphicShape( Poly, m_Pos + offset ); CreateGraphicShape( Poly, m_Pos + offset );
GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color ); GRPoly( clipbox, DC, Poly.size(), &Poly[0], 0, linewidth, color, color );
if( m_isDangling ) if( m_isDangling && panel )
DrawDanglingSymbol( panel, DC, m_Pos + offset, color ); DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
// Enable these line to draw the bounding box (debug tests purposes only) // Enable these line to draw the bounding box (debug tests purposes only)
......
...@@ -221,7 +221,7 @@ void PCB_EDIT_FRAME::Reset_Noroutable( wxDC* DC ) ...@@ -221,7 +221,7 @@ void PCB_EDIT_FRAME::Reset_Noroutable( wxDC* DC )
/* DEBUG Function: displays the routing matrix */ /* DEBUG Function: displays the routing matrix */
void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC ) void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
{ {
int dcell0, dcell1 = 0; int dcell0;
EDA_COLOR_T color; EDA_COLOR_T color;
int maxi = 600 / RoutingMatrix.m_Ncols; int maxi = 600 / RoutingMatrix.m_Ncols;
...@@ -242,14 +242,17 @@ void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC ) ...@@ -242,14 +242,17 @@ void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
if( dcell0 & HOLE ) if( dcell0 & HOLE )
color = GREEN; color = GREEN;
// if( RoutingMatrix.m_RoutingLayersCount ) #if 0
// dcell1 = GetCell( row, col, TOP ); int dcell1 = 0;
if( RoutingMatrix.m_RoutingLayersCount )
dcell1 = GetCell( row, col, TOP );
if( dcell1 & HOLE ) if( dcell1 & HOLE )
color = RED; color = RED;
// dcell0 |= dcell1; dcell0 |= dcell1;
#endif
if( !color && ( dcell0 & VIA_IMPOSSIBLE ) ) if( !color && ( dcell0 & VIA_IMPOSSIBLE ) )
color = BLUE; color = BLUE;
......
...@@ -303,53 +303,38 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC ) ...@@ -303,53 +303,38 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC )
{ {
wxSize newSize; wxSize newSize;
int newThickness; int newThickness;
TEXTE_PCB* pcbText = NULL;
TEXTE_MODULE* moduleText = NULL;
EDA_TEXT* text;
switch( aItem->Type() ) if( aItem->Type() == PCB_TEXT_T )
{ {
case PCB_TEXT_T:
newSize = GetDesignSettings().m_PcbTextSize; newSize = GetDesignSettings().m_PcbTextSize;
newThickness = GetDesignSettings().m_PcbTextWidth; newThickness = GetDesignSettings().m_PcbTextWidth;
pcbText = static_cast<TEXTE_PCB*>( aItem ); TEXTE_PCB* text = static_cast<TEXTE_PCB*>( aItem );
text = static_cast<EDA_TEXT*>( pcbText );
break;
case PCB_MODULE_TEXT_T:
newSize = GetDesignSettings().m_ModuleTextSize;
newThickness = GetDesignSettings().m_ModuleTextWidth;
moduleText = static_cast<TEXTE_MODULE*>( aItem );
text = static_cast<EDA_TEXT*>( moduleText );
break;
default:
// Exit if aItem is not a text field
return;
}
// Exit if there's nothing to do // Exit if there's nothing to do
if( text->GetSize() == newSize && text->GetThickness() == newThickness ) if( text->GetSize() == newSize && text->GetThickness() == newThickness )
return; return;
// Push item to undo list SaveCopyInUndoList( text, UR_CHANGED );
switch( aItem->Type() ) text->SetSize( newSize );
{ text->SetThickness( newThickness );
case PCB_TEXT_T: }
SaveCopyInUndoList( pcbText, UR_CHANGED );
break;
case PCB_MODULE_TEXT_T: else if( aItem->Type() == PCB_MODULE_TEXT_T )
SaveCopyInUndoList( moduleText->GetParent(), UR_CHANGED ); {
break; newSize = GetDesignSettings().m_ModuleTextSize;
newThickness = GetDesignSettings().m_ModuleTextWidth;
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( aItem );
default: // Exit if there's nothing to do
break; if( text->GetSize() == newSize && text->GetThickness() == newThickness )
} return;
// Apply changes SaveCopyInUndoList( text->GetParent(), UR_CHANGED );
text->SetSize( newSize ); text->SetSize( newSize );
text->SetThickness( newThickness ); text->SetThickness( newThickness );
}
else
return;
if( aDC ) if( aDC )
m_canvas->Refresh(); m_canvas->Refresh();
......
...@@ -572,6 +572,9 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in ...@@ -572,6 +572,9 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
syncLayerWidgetLayer(); syncLayerWidgetLayer();
syncRenderStates(); syncRenderStates();
// Update the tracks / vias available sizes list:
ReCreateAuxiliaryToolbar();
// Update the RATSNEST items, which were not loaded at the time // Update the RATSNEST items, which were not loaded at the time
// BOARD::SetVisibleElements() was called from within any PLUGIN. // BOARD::SetVisibleElements() was called from within any PLUGIN.
// See case RATSNEST_VISIBLE: in BOARD::SetElementVisibility() // See case RATSNEST_VISIBLE: in BOARD::SetElementVisibility()
......
...@@ -146,7 +146,8 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser() ...@@ -146,7 +146,8 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
wxString fpid; wxString fpid;
viewer->ShowModal( &fpid, this ); int ret = viewer->ShowModal( &fpid, this );
(void) ret; // make static analyser quiet
//DBG(printf("%s: fpid:'%s'\n", __func__, TO_UTF8( fpid ) );) //DBG(printf("%s: fpid:'%s'\n", __func__, TO_UTF8( fpid ) );)
......
...@@ -581,6 +581,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -581,6 +581,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_MODEDIT_CHECK: case ID_MODEDIT_CHECK:
// Currently: not implemented
break; break;
case ID_MODEDIT_EDIT_MODULE_PROPERTIES: case ID_MODEDIT_EDIT_MODULE_PROPERTIES:
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -137,10 +137,12 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar() ...@@ -137,10 +137,12 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddTool( ID_MODEDIT_PAD_SETTINGS, wxEmptyString, KiBitmap( options_pad_xpm ), m_mainToolBar->AddTool( ID_MODEDIT_PAD_SETTINGS, wxEmptyString, KiBitmap( options_pad_xpm ),
_( "Pad settings" ) ); _( "Pad settings" ) );
#if 0 // Currently there is no check footprint function defined, so do not show this tool
m_mainToolBar->AddSeparator(); m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_MODEDIT_CHECK, wxEmptyString, m_mainToolBar->AddTool( ID_MODEDIT_CHECK, wxEmptyString,
KiBitmap( module_check_xpm ), KiBitmap( module_check_xpm ),
_( "Check footprint" ) ); _( "Check footprint" ) );
#endif
// after adding the buttons to the toolbar, must call Realize() to reflect the changes // after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->Realize(); m_mainToolBar->Realize();
......
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