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.
This commit is contained in:
jean-pierre charras 2015-04-02 13:18:19 +02:00
parent 589dd442f5
commit bbbb84e6c2
16 changed files with 117 additions and 90 deletions

View File

@ -646,14 +646,14 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
bool useTextures = isRealisticMode() && isEnabled( FL_RENDER_TEXTURES );
// 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.
// So using 18 segments is a workaround to try to avoid these crashes
// ( We already used this trick in plot_board_layers.cpp,
// see PlotSolderMaskLayer() )
const int segcountforcircle = 18;
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
// for holes and items which do not need
// a fine representation
@ -767,13 +767,28 @@ void EDA_3D_CANVAS::buildBoard3DView( GLuint aBoardList, GLuint aBodyOnlyList,
for( ; pad; pad = pad->Next() )
{
// Calculate a factor to apply to segcount (bigger pad size -> more segments)
wxSize padSize = pad->GetSize();
int maxPadSize = glm::max( padSize.x, padSize.y );
float segFactor = (float)maxPadSize / (float)Millimeter2iu( 0.6 );
// Calculate a factor to apply to segcount for large holes ( > 1 mm)
// (bigger pad drill size -> more segments) because holes in pads can have
// very different sizes and optimizing this segcount gives a better look
// Mainly mounting holes have a size bigger thon 1 mm
wxSize padHole = pad->GetDrillSize();
pad->BuildPadDrillShapePolygon( allLayerHoles, 0,
(int)(segcountLowQuality * segFactor) );
if( ! padHole.x ) // Not drilled pad like SMD pad
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 );
}
}
}

View File

@ -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;
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;
}

View File

@ -83,11 +83,12 @@ int ParseVertex( FILE* File, glm::vec3 &dst_vertex );
/**
* Function ParseFloat
* parse a float value
* @param File file to read from
* @param dst_float destination float
* @return int - Return the number of floats readed (0 or 1)
* @param aFile file to read from
* @param aDstFloat destination float
* @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

View File

@ -1283,7 +1283,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "ambientIntensity" ) == 0 )
{
float ambientIntensity;
ParseFloat( m_file, &ambientIntensity );
ParseFloat( m_file, &ambientIntensity, 0.8 );
if( m_Master->m_use_modelfile_ambientIntensity == true )
{
@ -1294,7 +1294,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "transparency" ) == 0 )
{
float transparency;
ParseFloat( m_file, &transparency );
ParseFloat( m_file, &transparency, 0.0 );
if( m_Master->m_use_modelfile_transparency == true )
{
@ -1304,7 +1304,7 @@ int VRML2_MODEL_PARSER::read_Material()
else if( strcmp( text, "shininess" ) == 0 )
{
float shininess;
ParseFloat( m_file, &shininess );
ParseFloat( m_file, &shininess, 1.0 );
// VRML value is normalized and openGL expects a value 0 - 128
if( m_Master->m_use_modelfile_shininess == true )

View File

@ -455,7 +455,12 @@ void PDF_PLOTTER::closePdfStream()
wxASSERT( 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
fseek( workFile, 0, SEEK_SET );
@ -475,11 +480,11 @@ void PDF_PLOTTER::closePdfStream()
{
/* 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
stream! (a DEFLATE stream would be generated with -15 instead of 15)
rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15,
8, Z_DEFAULT_STRATEGY );
*/
* 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)
* rc = deflateInit2( &zstrm, Z_BEST_COMPRESSION, Z_DEFLATED, 15,
* 8, Z_DEFAULT_STRATEGY );
*/
wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );

View File

@ -170,6 +170,7 @@ TRIANGULATION::TRIANGULATION()
TRIANGULATION::TRIANGULATION( const TRIANGULATION& aTriangulation )
{
m_helper = 0; // make coverity and static analysers quiet.
// Triangulation: Copy constructor not present
assert( false );
}

View File

@ -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
// quasimodal mode for the quasimodal frame support to work. So don't use
// 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->MoveCursorToCrossHair();

View File

@ -196,6 +196,9 @@ DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::DataViewModel( LIB_PART& aPart ) :
m_GroupingColumn( 1 ),
m_UnitCount( m_Part.GetUnitCount() )
{
#ifdef REASSOCIATE_HACK
m_Widget = NULL;
#endif
aPart.GetPins( m_Backing );
/// @todo C++11
for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i )

View File

@ -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
// has no effect on objects that don't support hiding. If this is a close find
// dialog event, clear the temporary visibility flag.
if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
item->SetForceVisible( false );
else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() )
item->SetForceVisible( true );
if( item )
{
if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
item->SetForceVisible( false );
else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() )
item->SetForceVisible( true );
}
if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() )
{

View File

@ -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 );
EXCHG( linewidth, m_Thickness ); // set initial value
if( m_isDangling )
if( m_isDangling && panel)
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
// Enable these line to draw the bounding box (debug tests purposes only)
@ -1282,7 +1282,7 @@ void SCH_GLOBALLABEL::Draw( EDA_DRAW_PANEL* panel,
CreateGraphicShape( Poly, m_Pos + aOffset );
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 );
// Enable these line to draw the bounding box (debug tests purposes only)
@ -1614,7 +1614,7 @@ void SCH_HIERLABEL::Draw( EDA_DRAW_PANEL* panel,
CreateGraphicShape( Poly, m_Pos + offset );
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 );
// Enable these line to draw the bounding box (debug tests purposes only)

View File

@ -221,7 +221,7 @@ void PCB_EDIT_FRAME::Reset_Noroutable( wxDC* DC )
/* DEBUG Function: displays the routing matrix */
void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
{
int dcell0, dcell1 = 0;
int dcell0;
EDA_COLOR_T color;
int maxi = 600 / RoutingMatrix.m_Ncols;
@ -242,14 +242,17 @@ void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
if( dcell0 & HOLE )
color = GREEN;
// if( RoutingMatrix.m_RoutingLayersCount )
// dcell1 = GetCell( row, col, TOP );
#if 0
int dcell1 = 0;
if( RoutingMatrix.m_RoutingLayersCount )
dcell1 = GetCell( row, col, TOP );
if( dcell1 & HOLE )
color = RED;
// dcell0 |= dcell1;
dcell0 |= dcell1;
#endif
if( !color && ( dcell0 & VIA_IMPOSSIBLE ) )
color = BLUE;

View File

@ -303,54 +303,39 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC )
{
wxSize newSize;
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;
newThickness = GetDesignSettings().m_PcbTextWidth;
pcbText = static_cast<TEXTE_PCB*>( aItem );
text = static_cast<EDA_TEXT*>( pcbText );
break;
TEXTE_PCB* text = static_cast<TEXTE_PCB*>( aItem );
case PCB_MODULE_TEXT_T:
// Exit if there's nothing to do
if( text->GetSize() == newSize && text->GetThickness() == newThickness )
return;
SaveCopyInUndoList( text, UR_CHANGED );
text->SetSize( newSize );
text->SetThickness( newThickness );
}
else if( aItem->Type() == 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;
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( aItem );
default:
// Exit if aItem is not a text field
return;
// Exit if there's nothing to do
if( text->GetSize() == newSize && text->GetThickness() == newThickness )
return;
SaveCopyInUndoList( text->GetParent(), UR_CHANGED );
text->SetSize( newSize );
text->SetThickness( newThickness );
}
// Exit if there's nothing to do
if( text->GetSize() == newSize && text->GetThickness() == newThickness )
else
return;
// Push item to undo list
switch( aItem->Type() )
{
case PCB_TEXT_T:
SaveCopyInUndoList( pcbText, UR_CHANGED );
break;
case PCB_MODULE_TEXT_T:
SaveCopyInUndoList( moduleText->GetParent(), UR_CHANGED );
break;
default:
break;
}
// Apply changes
text->SetSize( newSize );
text->SetThickness( newThickness );
if( aDC )
m_canvas->Refresh();

View File

@ -572,6 +572,9 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
syncLayerWidgetLayer();
syncRenderStates();
// Update the tracks / vias available sizes list:
ReCreateAuxiliaryToolbar();
// Update the RATSNEST items, which were not loaded at the time
// BOARD::SetVisibleElements() was called from within any PLUGIN.
// See case RATSNEST_VISIBLE: in BOARD::SetElementVisibility()

View File

@ -146,7 +146,8 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
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 ) );)

View File

@ -581,6 +581,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_MODEDIT_CHECK:
// Currently: not implemented
break;
case ID_MODEDIT_EDIT_MODULE_PROPERTIES:

View File

@ -1,10 +1,10 @@
/*
* 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 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
* modify it under the terms of the GNU General Public License
@ -137,10 +137,12 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddTool( ID_MODEDIT_PAD_SETTINGS, wxEmptyString, KiBitmap( options_pad_xpm ),
_( "Pad settings" ) );
#if 0 // Currently there is no check footprint function defined, so do not show this tool
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_MODEDIT_CHECK, wxEmptyString,
KiBitmap( module_check_xpm ),
_( "Check footprint" ) );
#endif
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->Realize();