Core / Measure: Introduce QuickMeasure
This commit is contained in:
committed by
Yorik van Havre
parent
085ce0c54e
commit
818e122420
@@ -30,6 +30,8 @@
|
||||
#include <Gui/WidgetFactory.h>
|
||||
|
||||
#include "DlgPrefsMeasureAppearanceImp.h"
|
||||
#include "QuickMeasure.h"
|
||||
#include "QuickMeasurePy.h"
|
||||
#include "ViewProviderMeasureAngle.h"
|
||||
#include "ViewProviderMeasureDistance.h"
|
||||
#include "ViewProviderMeasureBase.h"
|
||||
@@ -86,7 +88,7 @@ PyMOD_INIT_FUNC(MeasureGui)
|
||||
CreateMeasureCommands();
|
||||
|
||||
MeasureGui::ViewProviderMeasureBase ::init();
|
||||
MeasureGui::ViewProviderMeasure ::init();
|
||||
MeasureGui::ViewProviderMeasure ::init();
|
||||
MeasureGui::ViewProviderMeasureAngle ::init();
|
||||
MeasureGui::ViewProviderMeasureDistance ::init();
|
||||
|
||||
@@ -95,5 +97,7 @@ PyMOD_INIT_FUNC(MeasureGui)
|
||||
|
||||
// Q_INIT_RESOURCE(Measure);
|
||||
|
||||
Base::Interpreter().addType(&MeasureGui::QuickMeasurePy::Type, mod, "QuickMeasure");
|
||||
|
||||
PyMOD_Return(mod);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ link_directories(${OCC_LIBRARY_DIR})
|
||||
|
||||
set(MeasureGui_LIBS
|
||||
Measure
|
||||
#Part
|
||||
FreeCADGui
|
||||
)
|
||||
|
||||
@@ -36,6 +37,8 @@ SET(MeasureGui_UIC_SRCS
|
||||
DlgPrefsMeasureAppearanceImp.ui
|
||||
)
|
||||
|
||||
generate_from_xml(QuickMeasurePy)
|
||||
|
||||
SET(MeasureGui_SRCS
|
||||
${CMAKE_SOURCE_DIR}/src/Mod/Measure/InitGui.py
|
||||
${MeasureGui_SRCS}
|
||||
@@ -44,6 +47,10 @@ SET(MeasureGui_SRCS
|
||||
Resources/Measure.qrc
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
QuickMeasurePy.xml
|
||||
QuickMeasurePyImp.cpp
|
||||
QuickMeasure.cpp
|
||||
QuickMeasure.h
|
||||
ViewProviderMeasureBase.cpp
|
||||
ViewProviderMeasureBase.h
|
||||
ViewProviderMeasureAngle.cpp
|
||||
|
||||
156
src/Mod/Measure/Gui/QuickMeasure.cpp
Normal file
156
src/Mod/Measure/Gui/QuickMeasure.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Pierre-Louis Boyer <development@Ondsel.com> *
|
||||
* *
|
||||
* 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 <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Link.h>
|
||||
#include <App/Part.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
|
||||
#include <Mod/Measure/App/Measurement.h>
|
||||
|
||||
#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<Part::TopoShape> subShapes;
|
||||
|
||||
std::vector<App::DocumentObject*> docsToMove;
|
||||
for (auto& selObj : Gui::Selection().getSelectionEx()) {
|
||||
App::DocumentObject* obj = selObj.getObject();
|
||||
const std::vector<std::string> 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::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::Surfaces) {
|
||||
Base::Quantity area(measurement->area(), Base::Unit::Area);
|
||||
print(tr("Total area: %1").arg(area.getUserString()));
|
||||
}
|
||||
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"
|
||||
57
src/Mod/Measure/Gui/QuickMeasure.h
Normal file
57
src/Mod/Measure/Gui/QuickMeasure.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Pierre-Louis Boyer <development@Ondsel.com> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef MEASUREGUI_QUICKMEASURE_H
|
||||
#define MEASUREGUI_QUICKMEASURE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <Mod/Measure/MeasureGlobal.h>
|
||||
|
||||
#include <Gui/Selection.h>
|
||||
namespace Measure {
|
||||
class Measurement;
|
||||
}
|
||||
|
||||
namespace MeasureGui {
|
||||
|
||||
class QuickMeasure : public QObject, Gui::SelectionObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QuickMeasure(QObject* parent = nullptr);
|
||||
~QuickMeasure() override;
|
||||
|
||||
private:
|
||||
void onSelectionChanged(const Gui::SelectionChanges& msg) override;
|
||||
|
||||
void print(const QString& message);
|
||||
|
||||
Measure::Measurement* measurement;
|
||||
|
||||
};
|
||||
|
||||
} //namespace MeasureGui
|
||||
|
||||
#endif // MEASUREGUI_QUICKMEASURE_H
|
||||
18
src/Mod/Measure/Gui/QuickMeasurePy.xml
Normal file
18
src/Mod/Measure/Gui/QuickMeasurePy.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="PyObjectBase"
|
||||
Name="QuickMeasurePy"
|
||||
Twin="QuickMeasure"
|
||||
TwinPointer="QuickMeasure"
|
||||
Include="Mod/Measure/Gui/QuickMeasure.h"
|
||||
Namespace="MeasureGui"
|
||||
FatherInclude="Base/PyObjectBase.h"
|
||||
Constructor="true"
|
||||
FatherNamespace="Base">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Ondsel" EMail="development@ondsel.com" />
|
||||
<UserDocu>Selection Observer for the QuickMeasure label.</UserDocu>
|
||||
</Documentation>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
64
src/Mod/Measure/Gui/QuickMeasurePyImp.cpp
Normal file
64
src/Mod/Measure/Gui/QuickMeasurePyImp.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Pierre-Louis Boyer <development@Ondsel.com> *
|
||||
* *
|
||||
* 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_
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
|
||||
// inclusion of the generated files (generated out of QuickMeasurePy.xml)
|
||||
#include "QuickMeasurePy.h"
|
||||
#include "QuickMeasurePy.cpp"
|
||||
|
||||
|
||||
using namespace MeasureGui;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string QuickMeasurePy::representation() const
|
||||
{
|
||||
return "<MeasureGui::QuickMeasure>";
|
||||
}
|
||||
|
||||
PyObject *QuickMeasurePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of BoundBoxPy and the Twin object
|
||||
return new QuickMeasurePy(new QuickMeasure);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int QuickMeasurePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *QuickMeasurePy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int QuickMeasurePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user