Skip to content

Commit

Permalink
Measure: add bounding box measurement
Browse files Browse the repository at this point in the history
Relates to GitHub #175
  • Loading branch information
HuguesDelorme committed Jan 29, 2024
1 parent 4e76085 commit aa68820
Show file tree
Hide file tree
Showing 19 changed files with 403 additions and 56 deletions.
9 changes: 6 additions & 3 deletions src/app/widget_gui_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ ButtonFlat* WidgetGuiDocument::createViewBtn(QWidget* parent, Theme::Icon icon,
const QColor bkgndColor =
m_qtOccView->supportsWidgetOpacity() ?
Qt::transparent :
mayoTheme()->color(Theme::Color::ButtonView3d_Background);
mayoTheme()->color(Theme::Color::ButtonView3d_Background)
;

auto btn = new ButtonFlat(parent);
btn->setBackgroundBrush(bkgndColor);
Expand Down Expand Up @@ -476,8 +477,10 @@ void WidgetGuiDocument::layoutViewControls()
case Aspect_TOTP_LEFT_LOWER:
return { ctrlXOffset, this->height() - viewCubeBndSize - margin - ctrlHeight };
case Aspect_TOTP_RIGHT_LOWER:
return { this->width() - viewCubeBndSize + ctrlXOffset,
this->height() - viewCubeBndSize - margin - ctrlHeight };
return {
this->width() - viewCubeBndSize + ctrlXOffset,
this->height() - viewCubeBndSize - margin - ctrlHeight
};
default:
return { margin, margin };
} // endswitch
Expand Down
33 changes: 28 additions & 5 deletions src/app/widget_measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ WidgetMeasure::WidgetMeasure(GuiDocument* guiDoc, QWidget* parent)
m_ui->combo_AreaUnit, qOverload<int>(&QComboBox::currentIndexChanged),
this, &WidgetMeasure::onMeasureUnitsChanged
);
QObject::connect(
m_ui->combo_VolumeUnit, qOverload<int>(&QComboBox::currentIndexChanged),
this, &WidgetMeasure::onMeasureUnitsChanged
);

this->onMeasureTypeChanged(m_ui->combo_MeasureType->currentIndex());
this->updateMessagePanel();
Expand Down Expand Up @@ -137,6 +141,7 @@ MeasureType WidgetMeasure::toMeasureType(int comboBoxId)
case 5: return MeasureType::Angle;
case 6: return MeasureType::Length;
case 7: return MeasureType::Area;
case 8: return MeasureType::BoundingBox;
}
return MeasureType::None;
}
Expand Down Expand Up @@ -176,19 +181,37 @@ AreaUnit WidgetMeasure::toMeasureAreaUnit(int comboBoxId)
return {};
}

VolumeUnit WidgetMeasure::toMeasureVolumeUnit(int comboBoxId)
{
switch (comboBoxId) {
case 0: return VolumeUnit::CubicMillimeter;
case 1: return VolumeUnit::CubicCentimeter;
case 2: return VolumeUnit::CubicMeter;
case 3: return VolumeUnit::CubicInch;
case 4: return VolumeUnit::CubicFoot;
case 5: return VolumeUnit::Liter;
case 6: return VolumeUnit::ImperialGallon;
case 7: return VolumeUnit::USGallon;
}
return {};
}

void WidgetMeasure::onMeasureTypeChanged(int id)
{
// Update widgets visibility
const MeasureType measureType = WidgetMeasure::toMeasureType(id);
const bool measureIsLengthBased = measureType != MeasureType::Angle;
const bool measureIsAngle = measureType == MeasureType::Angle;
const bool measureIsArea = measureType == MeasureType::Area;
const bool measureIsVolume = measureType == MeasureType::BoundingBox;
m_ui->label_LengthUnit->setVisible(measureIsLengthBased && !measureIsArea);
m_ui->combo_LengthUnit->setVisible(measureIsLengthBased && !measureIsArea);
m_ui->combo_LengthUnit->setVisible(m_ui->label_LengthUnit->isVisible());
m_ui->label_AngleUnit->setVisible(measureIsAngle);
m_ui->combo_AngleUnit->setVisible(measureIsAngle);
m_ui->combo_AngleUnit->setVisible(m_ui->label_AngleUnit->isVisible());
m_ui->label_AreaUnit->setVisible(measureIsArea);
m_ui->combo_AreaUnit->setVisible(measureIsArea);
m_ui->combo_AreaUnit->setVisible(m_ui->label_AreaUnit->isVisible());
m_ui->label_VolumeUnit->setVisible(measureIsVolume);
m_ui->combo_VolumeUnit->setVisible(m_ui->label_VolumeUnit->isVisible());

auto gfxScene = m_guiDoc->graphicsScene();

Expand Down Expand Up @@ -239,6 +262,7 @@ MeasureDisplayConfig WidgetMeasure::currentMeasureDisplayConfig() const
cfg.lengthUnit = WidgetMeasure::toMeasureLengthUnit(m_ui->combo_LengthUnit->currentIndex());
cfg.angleUnit = WidgetMeasure::toMeasureAngleUnit(m_ui->combo_AngleUnit->currentIndex());
cfg.areaUnit = WidgetMeasure::toMeasureAreaUnit(m_ui->combo_AreaUnit->currentIndex());
cfg.volumeUnit = WidgetMeasure::toMeasureVolumeUnit(m_ui->combo_VolumeUnit->currentIndex());
cfg.doubleToStringOptions.locale = AppModule::get()->stdLocale();
cfg.doubleToStringOptions.decimalCount = AppModule::get()->defaultTextOptions().unitDecimals;
cfg.devicePixelRatio = this->devicePixelRatioF();
Expand Down Expand Up @@ -335,8 +359,7 @@ void WidgetMeasure::onGraphicsSelectionChanged()
measure->update(measureDisplayConfig);
measure->adaptGraphics(gfxScene->v3dViewer()->Driver());
foreachGraphicsObject(measure, [=](const GraphicsObjectPtr& gfxObject) {
gfxObject->SetZLayer(Graphic3d_ZLayerId_Topmost);
gfxScene->addObject(gfxObject);
gfxScene->addObject(gfxObject, GraphicsScene::AddObjectDisableSelectionMode);
});

m_vecMeasureDisplay.push_back(std::move(measure));
Expand Down
1 change: 1 addition & 0 deletions src/app/widget_measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WidgetMeasure : public QWidget {
static LengthUnit toMeasureLengthUnit(int comboBoxId);
static AngleUnit toMeasureAngleUnit(int comboBoxId);
static AreaUnit toMeasureAreaUnit(int comboBoxId);
static VolumeUnit toMeasureVolumeUnit(int comboBoxId);

MeasureType currentMeasureType() const;
MeasureDisplayConfig currentMeasureDisplayConfig() const;
Expand Down
128 changes: 92 additions & 36 deletions src/app/widget_measure.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>229</width>
<height>156</height>
<width>246</width>
<height>158</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -33,6 +33,40 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="combo_AreaUnit">
<item>
<property name="text">
<string>Square Millimeter(mm²)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Centimeter(cm²)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Meter(m²)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Inch(in²)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Foot(ft²)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Yard(yd²)</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_LengthUnit">
<property name="text">
Expand All @@ -47,13 +81,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_AngleUnit">
<property name="text">
<string>Angle Unit</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_LengthUnit">
<item>
Expand Down Expand Up @@ -102,6 +129,41 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_AngleUnit">
<property name="text">
<string>Angle Unit</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget_Message" native="true">
<layout class="QVBoxLayout" name="layout_Message">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="widget_Void" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_VolumeUnit">
<property name="text">
<string>Volume Unit</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_MeasureType">
<item>
Expand Down Expand Up @@ -144,61 +206,55 @@
<string>Surface Area</string>
</property>
</item>
<item>
<property name="text">
<string>Bounding Box</string>
</property>
</item>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="combo_AreaUnit">
<item row="4" column="1">
<widget class="QComboBox" name="combo_VolumeUnit">
<item>
<property name="text">
<string>Square Millimeter(mm²)</string>
<string>Cubic Millimeter(mm³)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Centimeter(cm²)</string>
<string>Cubic Centimeter(cm³)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Meter(m²)</string>
<string>Cubic Meter(m³)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Inch(in²)</string>
<string>Cubic Inch(in³)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Foot(ft²)</string>
<string>Cubic Foot(ft³)</string>
</property>
</item>
<item>
<property name="text">
<string>Square Yard(yd²)</string>
<string>Liter(L)</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QWidget" name="widget_Message" native="true">
<layout class="QVBoxLayout" name="layout_Message">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
<item>
<property name="text">
<string>Imperial Gallon(GBgal)</string>
</property>
<property name="bottomMargin">
<number>0</number>
</item>
<item>
<property name="text">
<string>US Gallon(USgal)</string>
</property>
<item>
<widget class="QWidget" name="widget_Void" native="true"/>
</item>
</layout>
</item>
</widget>
</item>
</layout>
Expand Down
2 changes: 2 additions & 0 deletions src/base/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ constexpr QuantityVolume Quantity_CubicFoot(Quantity_Foot.value() * Quantity_Squ
constexpr QuantityVelocity Quantity_MillimeterPerSecond(1.);

constexpr QuantityVolume Quantity_Liter(1e6);
constexpr QuantityVolume Quantity_ImperialGallon(1e6 * 4.54609);
constexpr QuantityVolume Quantity_USGallon(1e6 * 3.785411784);

constexpr QuantityMass Quantity_Microgram(1e-9);
constexpr QuantityMass Quantity_Milligram(1e-6);
Expand Down
9 changes: 9 additions & 0 deletions src/base/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ enum AreaUnit {
SquareInch, SquareFoot, SquareYard, SquareMile
};

enum VolumeUnit {
// SI
CubicMillimeter, CubicCentimeter, CubicMeter,
// Imperial UK
CubicInch, CubicFoot,
// Others
Liter, ImperialGallon, USGallon
};

#if 0
enum class BaseUnit {
Length = 0, // Meter(m)
Expand Down
21 changes: 21 additions & 0 deletions src/base/unit_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@ UnitSystem::TranslateResult UnitSystem::translateArea(QuantityArea area, AreaUni
return {};
}

UnitSystem::TranslateResult UnitSystem::translateVolume(QuantityVolume volume, VolumeUnit unit)
{
auto fnTrResult = [=](QuantityVolume qtyFactor, const char* strUnit) {
return Internal::translateHelper(volume, qtyFactor, strUnit);
};
switch (unit) {
// SI
case VolumeUnit::CubicMillimeter: return fnTrResult(Quantity_CubicMillimeter, "mm³");
case VolumeUnit::CubicCentimeter: return fnTrResult(Quantity_CubicCentimeter, "cm³");
case VolumeUnit::CubicMeter: return fnTrResult(Quantity_CubicMeter, "");
// Imperial UK
case VolumeUnit::CubicInch: return fnTrResult(Quantity_CubicInch, "in³");
case VolumeUnit::CubicFoot: return fnTrResult(Quantity_CubicFoot, "ft³");
// Others
case VolumeUnit::Liter: return fnTrResult(Quantity_Liter, "L");
case VolumeUnit::ImperialGallon: return fnTrResult(Quantity_ImperialGallon, "GBgal");
case VolumeUnit::USGallon: return fnTrResult(Quantity_USGallon, "USgal");
}
return {};
}

UnitSystem::TranslateResult UnitSystem::translateAngle(QuantityAngle angle, AngleUnit unit)
{
switch (unit) {
Expand Down
1 change: 1 addition & 0 deletions src/base/unit_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class UnitSystem {

static TranslateResult translateLength(QuantityLength length, LengthUnit unit);
static TranslateResult translateArea(QuantityArea area, AreaUnit unit);
static TranslateResult translateVolume(QuantityVolume volume, VolumeUnit unit);
static TranslateResult translateAngle(QuantityAngle angle, AngleUnit unit);

static TranslateResult radians(QuantityAngle angle);
Expand Down
Loading

0 comments on commit aa68820

Please sign in to comment.