From 7c37641d83231d227599fec7f528149647521ea6 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 25 Aug 2019 08:46:53 -0700 Subject: [PATCH] pcbnew: Partial board stats cleanup Fixes ordering issue and int/double conversion in board area Moves via casting to internal dyn_cast --- pcbnew/dialogs/dialog_board_statistics.cpp | 45 +++++++++------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/pcbnew/dialogs/dialog_board_statistics.cpp b/pcbnew/dialogs/dialog_board_statistics.cpp index 55904d3c0e..ad304b9e61 100644 --- a/pcbnew/dialogs/dialog_board_statistics.cpp +++ b/pcbnew/dialogs/dialog_board_statistics.cpp @@ -213,23 +213,16 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB() } // Get vias count - VIA* via; for( auto& track : board->Tracks() ) { - if( track->Type() == PCB_VIA_T ) + if( auto via = dyn_cast( track ) ) { - via = dynamic_cast( track ); - - // We have to check if cast was successful - if( via ) + for( auto& type : m_viasTypes ) { - for( auto& type : m_viasTypes ) + if( via->GetViaType() == type.attribute ) { - if( via->GetViaType() == type.attribute ) - { - type.qty++; - break; - } + type.qty++; + break; } } } @@ -257,12 +250,12 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB() if( m_hasOutline ) { - m_boardArea = 0; - int outlinesCount = polySet.OutlineCount(); - for( int i = 0; i < outlinesCount; i++ ) + m_boardArea = 0.0; + + for( int i = 0; i < polySet.OutlineCount(); i++ ) { SHAPE_LINE_CHAIN& outline = polySet.Outline( i ); - m_boardArea += abs( outline.Area() ); + m_boardArea += std::fabs( outline.Area() ); // If checkbox "subtract holes" is checked if( m_checkBoxSubtractHoles->GetValue() ) @@ -271,11 +264,6 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB() m_boardArea -= std::fabs( polySet.Hole( i, j ).Area() ); } - if( GetUserUnits() == INCHES ) - m_boardArea /= ( IU_PER_MILS * IU_PER_MILS * 1000000 ); - else - m_boardArea /= ( IU_PER_MM * IU_PER_MM ); - if( boundingBoxCreated ) { bbox.Merge( outline.BBox() ); @@ -287,6 +275,11 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB() } } + if( GetUserUnits() == INCHES ) + m_boardArea /= ( IU_PER_MILS * IU_PER_MILS * 1000000 ); + else + m_boardArea /= ( IU_PER_MM * IU_PER_MM ); + m_boardWidth = bbox.GetWidth(); m_boardHeight = bbox.GetHeight(); } @@ -453,7 +446,7 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& event ) // We will save data about components in the table. // We have to calculate column widths - size_t colsWidth[4]; + int colsWidth[4]; wxString columns[4] = { "", _( "Front Side" ), _( "Back Side" ), _( "Total" ) }; wxString tmp; @@ -466,18 +459,18 @@ void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& event ) for( auto& type : m_componentsTypes ) { // Get maximum width for left label column - colsWidth[0] = std::max( type.title.size(), colsWidth[0] ); + colsWidth[0] = std::max( type.title.size(), colsWidth[0] ); frontTotal += type.frontSideQty; backTotal += type.backSideQty; } // Get maximum width for other columns tmp.Printf( "%d", frontTotal ); - colsWidth[1] = std::max( tmp.size(), colsWidth[1] ); + colsWidth[1] = std::max( tmp.size(), colsWidth[1] ); tmp.Printf( "%d", backTotal ); - colsWidth[2] = std::max( tmp.size(), colsWidth[2] ); + colsWidth[2] = std::max( tmp.size(), colsWidth[2] ); tmp.Printf( "%d", frontTotal + backTotal ); - colsWidth[3] = std::max( tmp.size(), colsWidth[3] ); + colsWidth[3] = std::max( tmp.size(), colsWidth[3] ); //Write components amount to file msg << "\n";