/*************************************************************************** * Copyright (c) 2023 Pierre-Louis Boyer * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ #include #include #include #include #include #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "QuickMeasure.h" using namespace Measure; using namespace MeasureGui; QuickMeasure::QuickMeasure(QObject* parent) : QObject(parent) { measurement = new Measure::Measurement(); } QuickMeasure::~QuickMeasure() { delete measurement; } void QuickMeasure::onSelectionChanged(const Gui::SelectionChanges& msg) { if (msg.Type == Gui::SelectionChanges::SetPreselect || msg.Type == Gui::SelectionChanges::RmvPreselect) { return; } Gui::Document* doc = Gui::Application::Instance->activeDocument(); if (!doc) { return; } measurement->clear(); std::vector subShapes; std::vector docsToMove; for (auto& selObj : Gui::Selection().getSelectionEx()) { App::DocumentObject* obj = selObj.getObject(); const std::vector subNames = selObj.getSubNames(); if (subNames.empty()) { measurement->addReference3D(obj, ""); } else { for (auto& subName : subNames) { measurement->addReference3D(obj, subName); } } } MeasureType mtype = measurement->getType(); if (mtype == MeasureType::Surfaces) { Base::Quantity area(measurement->area(), Base::Unit::Area); print(tr("Total area: %1").arg(area.getUserString())); } /* deactivated because computing the volumes/area of solids makes a significant slow down in selection of complex solids. else if (mtype == MeasureType::Volumes) { Base::Quantity area(measurement->area(), Base::Unit::Area); Base::Quantity vol(measurement->volume(), Base::Unit::Volume); print(tr("Volume: %1, Area: %2").arg(vol.getSafeUserString()).arg(area.getSafeUserString())); }*/ else if (mtype == MeasureType::TwoPlanes) { Base::Quantity dist(measurement->planePlaneDistance(), Base::Unit::Length); print(tr("Nominal distance: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::Cone || mtype == MeasureType::Plane) { Base::Quantity area(measurement->area(), Base::Unit::Area); print(tr("Area: %1").arg(area.getUserString())); } else if (mtype == MeasureType::Cylinder || mtype == MeasureType::Sphere || mtype == MeasureType::Torus) { Base::Quantity area(measurement->area(), Base::Unit::Area); Base::Quantity rad(measurement->radius(), Base::Unit::Length); print(tr("Area: %1, Radius: %2").arg(area.getSafeUserString()).arg(rad.getSafeUserString())); } else if (mtype == MeasureType::Edges) { Base::Quantity dist(measurement->length(), Base::Unit::Length); print(tr("Total length: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::TwoParallelLines) { Base::Quantity dist(measurement->lineLineDistance(), Base::Unit::Length); print(tr("Nominal distance: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::TwoLines) { Base::Quantity angle(measurement->angle(), Base::Unit::Length); Base::Quantity dist(measurement->length(), Base::Unit::Length); print(tr("Angle: %1, Total length: %2").arg(angle.getSafeUserString()).arg(dist.getSafeUserString())); } else if (mtype == MeasureType::Line) { Base::Quantity dist(measurement->length(), Base::Unit::Length); print(tr("Length: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::Circle) { Base::Quantity dist(measurement->radius(), Base::Unit::Length); print(tr("Radius: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::PointToPoint) { Base::Quantity dist(measurement->length(), Base::Unit::Length); print(tr("Distance: %1").arg(dist.getSafeUserString())); } else if (mtype == MeasureType::PointToEdge || mtype == MeasureType::PointToSurface) { Base::Quantity dist(measurement->length(), Base::Unit::Length); print(tr("Minimum distance: %1").arg(dist.getSafeUserString())); } else { print(QString::fromLatin1("")); } } void QuickMeasure::print(const QString& message) { Gui::getMainWindow()->setRightSideMessage(message); } #include "moc_QuickMeasure.cpp"