Merge pull request #13810 from hlorus/replace_measuredistance
Integrate Std_MeasureDistance into unified measurement facility
This commit is contained in:
@@ -93,10 +93,12 @@ PyMOD_INIT_FUNC(Measure)
|
||||
Measure::Measurement ::init();
|
||||
|
||||
// umf classes
|
||||
Measure::MeasureDistanceType ::init();
|
||||
Measure::MeasureBase ::init();
|
||||
Measure::MeasurePython ::init();
|
||||
Measure::MeasureAngle ::init();
|
||||
Measure::MeasureDistance ::init();
|
||||
Measure::MeasureDistanceDetached::init();
|
||||
Measure::MeasurePosition ::init();
|
||||
Measure::MeasureLength ::init();
|
||||
Measure::MeasureArea ::init();
|
||||
@@ -111,6 +113,13 @@ PyMOD_INIT_FUNC(Measure)
|
||||
MeasureDistance::isPrioritizedSelection
|
||||
);
|
||||
|
||||
App::MeasureManager::addMeasureType("DISTANCEFREE",
|
||||
"Distance Free",
|
||||
"Measure::MeasureDistanceDetached",
|
||||
MeasureDistanceDetached::isValidSelection,
|
||||
nullptr
|
||||
);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"ANGLE",
|
||||
"Angle",
|
||||
|
||||
@@ -229,3 +229,105 @@ std::vector<App::DocumentObject*> MeasureDistance::getSubject() const
|
||||
return {Element1.getValue()};
|
||||
}
|
||||
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Measure::MeasureDistanceDetached, Measure::MeasureBase)
|
||||
|
||||
MeasureDistanceDetached::MeasureDistanceDetached()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Distance,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Distance between the two elements");
|
||||
Distance.setUnit(Base::Unit::Length);
|
||||
|
||||
ADD_PROPERTY_TYPE(Position1,(Base::Vector3d(0.0,0.0,0.0)),"Measurement", App::Prop_None, "Position1");
|
||||
ADD_PROPERTY_TYPE(Position2,(Base::Vector3d(0.0,1.0,0.0)),"Measurement", App::Prop_None, "Position2");
|
||||
}
|
||||
|
||||
MeasureDistanceDetached::~MeasureDistanceDetached() = default;
|
||||
|
||||
|
||||
bool MeasureDistanceDetached::isValidSelection(const App::MeasureSelection& selection){
|
||||
return selection.size() == 2;
|
||||
}
|
||||
|
||||
void MeasureDistanceDetached::parseSelection(const App::MeasureSelection& selection) {
|
||||
auto sel1 = selection.at(0);
|
||||
auto sel2 = selection.at(1);
|
||||
|
||||
Position1.setValue(sel1.pickedPoint);
|
||||
Position2.setValue(sel2.pickedPoint);
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureDistanceDetached::execute()
|
||||
{
|
||||
recalculateDistance();
|
||||
return DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void MeasureDistanceDetached::recalculateDistance()
|
||||
{
|
||||
auto delta = Position1.getValue() - Position2.getValue();
|
||||
Distance.setValue(delta.Length());
|
||||
}
|
||||
|
||||
void MeasureDistanceDetached::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (isRestoring() || isRemoving()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop == &Position1 || prop == &Position2) {
|
||||
recalculateDistance();
|
||||
}
|
||||
|
||||
MeasureBase::onChanged(prop);
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> MeasureDistanceDetached::getSubject() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Base::Type MeasureDistanceType::getClassTypeId()
|
||||
{
|
||||
return Base::Type::badType();
|
||||
}
|
||||
|
||||
Base::Type MeasureDistanceType::getTypeId() const
|
||||
{
|
||||
return Base::Type::badType();
|
||||
}
|
||||
|
||||
void MeasureDistanceType::init()
|
||||
{
|
||||
initSubclass(MeasureDistanceType::classTypeId,
|
||||
"App::MeasureDistance",
|
||||
"App::DocumentObject",
|
||||
&(MeasureDistanceType::create));
|
||||
}
|
||||
|
||||
void* MeasureDistanceType::create()
|
||||
{
|
||||
return new MeasureDistanceDetached();
|
||||
}
|
||||
|
||||
Base::Type MeasureDistanceType::classTypeId = Base::Type::badType();
|
||||
|
||||
|
||||
|
||||
// Migrate old MeasureDistance Type
|
||||
void MeasureDistanceDetached::handleChangedPropertyName(Base::XMLReader &reader,
|
||||
const char * TypeName,
|
||||
const char *PropName)
|
||||
{
|
||||
if (strcmp(PropName, "P1") == 0 && strcmp(TypeName, "App::PropertyVector") == 0) {
|
||||
Position1.Restore(reader);
|
||||
}
|
||||
else if (strcmp(PropName, "P2") == 0 && strcmp(TypeName, "App::PropertyVector") == 0) {
|
||||
Position2.Restore(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,17 @@
|
||||
namespace Measure
|
||||
{
|
||||
|
||||
class MeasureDistanceType: public Base::BaseClass
|
||||
{
|
||||
public:
|
||||
static Base::Type getClassTypeId();
|
||||
Base::Type getTypeId() const override;
|
||||
static void init();
|
||||
static void* create();
|
||||
|
||||
private:
|
||||
static Base::Type classTypeId;
|
||||
};
|
||||
|
||||
|
||||
class MeasureExport MeasureDistance : public Measure::MeasureBaseExtendable<Part::MeasureDistanceInfo>
|
||||
@@ -81,6 +92,50 @@ private:
|
||||
void onChanged(const App::Property* prop) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MeasureExport MeasureDistanceDetached : public Measure::MeasureBase
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureDistanceDetached);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
MeasureDistanceDetached();
|
||||
~MeasureDistanceDetached() override;
|
||||
|
||||
App::PropertyDistance Distance;
|
||||
|
||||
App::PropertyVector Position1;
|
||||
App::PropertyVector Position2;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
void recalculateDistance();
|
||||
|
||||
const char* getViewProviderName() const override {
|
||||
return "MeasureGui::ViewProviderMeasureDistance";
|
||||
}
|
||||
|
||||
static bool isValidSelection(const App::MeasureSelection& selection);
|
||||
void parseSelection(const App::MeasureSelection& selection) override;
|
||||
|
||||
std::vector<std::string> getInputProps() override {return {"Position1", "Position2"};}
|
||||
App::Property* getResultProp() override {return &this->Distance;}
|
||||
|
||||
// Return the object we are measuring
|
||||
std::vector<App::DocumentObject*> getSubject() const override;
|
||||
|
||||
void handleChangedPropertyName(Base::XMLReader &reader,
|
||||
const char * TypeName,
|
||||
const char *PropName) override;
|
||||
|
||||
private:
|
||||
void onChanged(const App::Property* prop) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace Measure
|
||||
|
||||
|
||||
|
||||
@@ -436,12 +436,15 @@ bool ViewProviderMeasureBase::isSubjectVisible()
|
||||
}
|
||||
|
||||
// we need these things to proceed
|
||||
if (!getMeasureObject() ||
|
||||
getMeasureObject()->getSubject().empty() ||
|
||||
!guiDoc ) {
|
||||
if (!getMeasureObject() || !guiDoc ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show the measurement if it doesn't track any subjects
|
||||
if (getMeasureObject()->getSubject().empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto & obj : getMeasureObject()->getSubject()) {
|
||||
Gui::ViewProvider* vp = guiDoc->getViewProvider(obj);
|
||||
if (!vp || !vp->isVisible()) {
|
||||
|
||||
@@ -42,10 +42,9 @@
|
||||
#include <Gui/Inventor/MarkerBitmaps.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/MeasureDistance.h>
|
||||
#include <Base/BaseClass.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include "Mod/Measure/App/MeasureDistance.h"
|
||||
#include <Mod/Measure/App/Preferences.h>
|
||||
|
||||
#include "ViewProviderMeasureDistance.h"
|
||||
@@ -63,9 +62,19 @@ PROPERTY_SOURCE(MeasureGui::ViewProviderMeasureDistance, MeasureGui::ViewProvide
|
||||
|
||||
|
||||
SbMatrix ViewProviderMeasureDistance::getMatrix() {
|
||||
auto object = dynamic_cast<Measure::MeasureDistance*>(getObject());
|
||||
auto vec1 = object->Position1.getValue();
|
||||
auto vec2 = object->Position2.getValue();
|
||||
if (!pcObject) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto prop1 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position1"));
|
||||
auto prop2 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position2"));
|
||||
|
||||
if (!prop1 || !prop2) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto vec1 = prop1->getValue();
|
||||
auto vec2 = prop2->getValue();
|
||||
|
||||
const double tolerance(10.0e-6);
|
||||
SbVec3f origin = toSbVec3f((vec2 + vec1) / 2);
|
||||
@@ -186,26 +195,28 @@ ViewProviderMeasureDistance::~ViewProviderMeasureDistance()
|
||||
}
|
||||
|
||||
|
||||
Measure::MeasureDistance* ViewProviderMeasureDistance::getMeasureDistance()
|
||||
{
|
||||
Measure::MeasureDistance* feature = dynamic_cast<Measure::MeasureDistance*>(pcObject);
|
||||
if (!feature) {
|
||||
throw Base::RuntimeError("Feature not found for ViewProviderMeasureDistance");
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
//! repaint the annotation
|
||||
void ViewProviderMeasureDistance::redrawAnnotation()
|
||||
{
|
||||
auto object = dynamic_cast<Measure::MeasureDistance*>(getObject());
|
||||
auto vec1 = object->Position1.getValue();
|
||||
auto vec2 = object->Position2.getValue();
|
||||
if (!pcObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto prop1 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position1"));
|
||||
auto prop2 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position2"));
|
||||
|
||||
if (!prop1 || !prop2) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto vec1 = prop1->getValue();
|
||||
auto vec2 = prop2->getValue();
|
||||
|
||||
// Set the distance
|
||||
fieldDistance = (vec2 - vec1).Length();
|
||||
|
||||
setLabelValue(object->Distance.getQuantityValue().getUserString());
|
||||
auto propDistance = dynamic_cast<App::PropertyDistance*>(pcObject->getPropertyByName("Distance"));
|
||||
setLabelValue(propDistance->getQuantityValue().getUserString());
|
||||
|
||||
// Set matrix
|
||||
SbMatrix matrix = getMatrix();
|
||||
|
||||
@@ -23,14 +23,12 @@
|
||||
#ifndef MEASUREGUI_VIEWPROVIDERMEASUREDISTANCE_H
|
||||
#define MEASUREGUI_VIEWPROVIDERMEASUREDISTANCE_H
|
||||
|
||||
#include <Mod/Measure/MeasureGlobal.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <Mod/Measure/App/MeasureDistance.h>
|
||||
|
||||
#include <Mod/Measure/MeasureGlobal.h>
|
||||
#include "ViewProviderMeasureBase.h"
|
||||
|
||||
|
||||
class SoCoordinate3;
|
||||
class SoIndexedLineSet;
|
||||
|
||||
@@ -47,7 +45,6 @@ public:
|
||||
ViewProviderMeasureDistance();
|
||||
~ViewProviderMeasureDistance() override;
|
||||
|
||||
Measure::MeasureDistance* getMeasureDistance();
|
||||
void redrawAnnotation() override;
|
||||
void positionAnno(const Measure::MeasureBase* measureObject) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user