diff --git a/common/base_units.cpp b/common/base_units.cpp index 13da3b54a5..0c42fd4a82 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -124,25 +124,40 @@ double To_User_Unit( EDA_UNITS aUnit, double aValue, bool aUseMils ) */ // A lower-precision (for readability) version of StringFromValue() -wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aUseMils ) +wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType ) { return MessageTextFromValue( aUnits, double( aValue ), aUseMils ); } // A lower-precision (for readability) version of StringFromValue() -wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aUseMils ) +wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, + bool aUseMils, EDA_DATA_TYPE aType ) { return MessageTextFromValue( aUnits, double( aValue ), aUseMils ); } // A lower-precision (for readability) version of StringFromValue() -wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils ) +wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils, EDA_DATA_TYPE aType ) { wxString text; const wxChar* format; - double value = To_User_Unit( aUnits, aValue, aUseMils ); + double value = aValue; + + switch( aType ) + { + case EDA_DATA_TYPE::VOLUME: + value = To_User_Unit( aUnits, value, aUseMils ); + // Fall through to continue computation + + case EDA_DATA_TYPE::AREA: + value = To_User_Unit( aUnits, value, aUseMils ); + // Fall through to continue computation + + case EDA_DATA_TYPE::DISTANCE: + value = To_User_Unit( aUnits, value, aUseMils ); + } if( aUnits == EDA_UNITS::INCHES ) { @@ -175,7 +190,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils ) text.Printf( format, value ); text += " "; - text += GetAbbreviatedUnitsLabel( aUnits, aUseMils ); + text += GetAbbreviatedUnitsLabel( aUnits, aUseMils, aType ); return text; } @@ -449,18 +464,46 @@ wxString AngleToStringDegrees( double aAngle ) } -wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, bool aUseMils ) +wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType ) { switch( aUnit ) { case EDA_UNITS::INCHES: if( aUseMils ) - return _( "mils" ); + { + switch( aType ) + { + case EDA_DATA_TYPE::DISTANCE: + return _( "mils" ); + case EDA_DATA_TYPE::AREA: + return _( "sq. mils" ); + case EDA_DATA_TYPE::VOLUME: + return _( "cu. mils" ); + } + } else - return _( "in" ); + { + switch( aType ) + { + case EDA_DATA_TYPE::DISTANCE: + return _( "in" ); + case EDA_DATA_TYPE::AREA: + return _( "sq. in" ); + case EDA_DATA_TYPE::VOLUME: + return _( "cu. in" ); + } + } case EDA_UNITS::MILLIMETRES: - return _( "mm" ); + switch( aType ) + { + case EDA_DATA_TYPE::DISTANCE: + return _( "mm" ); + case EDA_DATA_TYPE::AREA: + return _( "sq. mm" ); + case EDA_DATA_TYPE::VOLUME: + return _( "cu. mm" ); + } case EDA_UNITS::PERCENT: return _( "%" ); diff --git a/include/base_units.h b/include/base_units.h index a8371921d1..281088657e 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -107,13 +107,17 @@ wxString AngleToStringDegrees( double aAngle ); * message text. * @param aValue The double value to convert. * @param aUseMils Convert inch values to mils if true. + * @param aType Type of the unit being used (e.g. distance, area, etc.) * @return The converted string for display in user interface elements. */ -wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils = false ); +wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils = false, + EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE ); -wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aUseMils = false ); +wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aUseMils = false, + EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE ); -wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aUseMils = false ); +wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aUseMils = false, + EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE ); /** * Function StringFromValue @@ -177,9 +181,12 @@ void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits, bool& * Get the units string for a given units type. * * @param aUnits - The units requested. + * @param aUseMils - Use mils for the unit + * @param aType - The data type of the unit (e.g. distance, area, etc.) * @return The human readable units string. */ -wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, bool aUseMils = false ); +wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, bool aUseMils = false, + EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE ); /** * Function FormatInternalUnits diff --git a/include/common.h b/include/common.h index 042a3ab661..d35e361023 100644 --- a/include/common.h +++ b/include/common.h @@ -69,6 +69,16 @@ typedef uint32_t timestamp_t; #define TEXT_ANGLE_HORIZ 0 #define TEXT_ANGLE_VERT 900 +/** + * The type of unit. + */ +enum class EDA_DATA_TYPE +{ + DISTANCE = 0, + AREA = 1, + VOLUME = 2 +}; + enum class EDA_UNITS { INCHES = 0, diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 3907440582..ef40f4b29a 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -44,7 +44,8 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent, bool aInModule ) - : BOARD_CONNECTED_ITEM( aParent, aInModule ? PCB_MODULE_ZONE_AREA_T : PCB_ZONE_AREA_T ) + : BOARD_CONNECTED_ITEM( aParent, aInModule ? PCB_MODULE_ZONE_AREA_T : PCB_ZONE_AREA_T ), + m_area( 0.0 ) { m_CornerSelection = nullptr; // no corner is selected m_IsFilled = false; // fill status : true when the zone is filled @@ -753,6 +754,9 @@ void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector m_insulatedIslands; bool m_hv45; // constrain edges to horizontal, vertical or 45ยบ + + double m_area; // The filled zone area }; diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 18f3f26232..79532c31e3 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -3889,7 +3889,10 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent ) } if( !pts.IsEmpty() ) + { zone->SetFilledPolysList( pts ); + zone->CalculateFilledArea(); + } // Ensure keepout and non copper zones do not have a net // (which have no sense for these zones) diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index cd804a999b..275e453b60 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -241,6 +241,7 @@ bool ZONE_FILLER::Fill( const std::vector& aZones, bool aCheck } zone.m_zone->SetFilledPolysList( poly ); + zone.m_zone->CalculateFilledArea(); if( aCheck && zone.m_zone->GetHashValue() != poly.GetHash() ) outOfDate = true;