Merge pull request #16045 from wwmayer/format_measure

Measure: Prepare for clang-format
This commit is contained in:
Chris Hennes
2024-08-26 10:57:13 -05:00
committed by GitHub
47 changed files with 1387 additions and 1045 deletions

View File

@@ -17,6 +17,7 @@ files: |
src/Mod/Import|
src/Mod/Inspection|
src/Mod/JtReader|
src/Mod/Measure|
src/Mod/Mesh|
src/Mod/MeshPart|
src/Mod/Plot|

View File

@@ -43,7 +43,8 @@
#include "MeasureArea.h"
#include "MeasureRadius.h"
namespace Measure {
namespace Measure
{
// explicit template instantiations
template class MeasureExport MeasureBaseExtendable<Part::MeasureAngleInfo>;
@@ -57,7 +58,8 @@ template class MeasureExport MeasureBaseExtendable<Part::MeasureRadiusInfo>;
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Measure")
Module()
: Py::ExtensionModule<Module>("Measure")
{
initialize("This module is the Measure module."); // register with Python
}
@@ -110,80 +112,74 @@ PyMOD_INIT_FUNC(Measure)
"Distance",
"Measure::MeasureDistance",
MeasureDistance::isValidSelection,
MeasureDistance::isPrioritizedSelection
);
MeasureDistance::isPrioritizedSelection);
App::MeasureManager::addMeasureType("DISTANCEFREE",
"Distance Free",
"Measure::MeasureDistanceDetached",
MeasureDistanceDetached::isValidSelection,
nullptr
);
nullptr);
App::MeasureManager::addMeasureType(
"ANGLE",
App::MeasureManager::addMeasureType("ANGLE",
"Angle",
"Measure::MeasureAngle",
MeasureAngle::isValidSelection,
MeasureAngle::isPrioritizedSelection
);
MeasureAngle::isPrioritizedSelection);
App::MeasureManager::addMeasureType(
"LENGTH",
App::MeasureManager::addMeasureType("LENGTH",
"Length",
"Measure::MeasureLength",
MeasureLength::isValidSelection,
nullptr
);
nullptr);
App::MeasureManager::addMeasureType(
"POSITION",
App::MeasureManager::addMeasureType("POSITION",
"Position",
"Measure::MeasurePosition",
MeasurePosition::isValidSelection,
nullptr
);
nullptr);
App::MeasureManager::addMeasureType(
"AREA",
App::MeasureManager::addMeasureType("AREA",
"Area",
"Measure::MeasureArea",
MeasureArea::isValidSelection,
nullptr
);
nullptr);
App::MeasureManager::addMeasureType(
"RADIUS",
App::MeasureManager::addMeasureType("RADIUS",
"Radius",
"Measure::MeasureRadius",
MeasureRadius::isValidSelection,
MeasureRadius::isPrioritizedSelection
);
MeasureRadius::isPrioritizedSelection);
// load measure callbacks from Part module
auto lengthList = Part::MeasureClient::reportLengthCB();
for (auto& entry : lengthList) {
MeasureBaseExtendable<Part::MeasureLengthInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasureLengthInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}
auto angleList = Part::MeasureClient::reportAngleCB();
for (auto& entry : angleList) {
MeasureBaseExtendable<Part::MeasureAngleInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasureAngleInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}
auto areaList = Part::MeasureClient::reportAreaCB();
for (auto& entry : areaList) {
MeasureBaseExtendable<Part::MeasureAreaInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasureAreaInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}
auto distanceList = Part::MeasureClient::reportDistanceCB();
for (auto& entry : distanceList) {
MeasureBaseExtendable<Part::MeasureDistanceInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasureDistanceInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}
auto positionList = Part::MeasureClient::reportPositionCB();
for (auto& entry : positionList) {
MeasureBaseExtendable<Part::MeasurePositionInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasurePositionInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}
auto radiusList = Part::MeasureClient::reportRadiusCB();
for (auto& entry : radiusList) {
MeasureBaseExtendable<Part::MeasureRadiusInfo>::addGeometryHandler(entry.m_module, entry.m_callback);
MeasureBaseExtendable<Part::MeasureRadiusInfo>::addGeometryHandler(entry.m_module,
entry.m_callback);
}

View File

@@ -38,15 +38,26 @@ PROPERTY_SOURCE(Measure::MeasureAngle, Measure::MeasureBase)
MeasureAngle::MeasureAngle()
{
ADD_PROPERTY_TYPE(Element1,(nullptr), "Measurement", App::Prop_None, "First element of the measurement");
ADD_PROPERTY_TYPE(Element1,
(nullptr),
"Measurement",
App::Prop_None,
"First element of the measurement");
Element1.setScope(App::LinkScope::Global);
Element1.setAllowExternal(true);
ADD_PROPERTY_TYPE(Element2,(nullptr), "Measurement", App::Prop_None, "Second element of the measurement");
ADD_PROPERTY_TYPE(Element2,
(nullptr),
"Measurement",
App::Prop_None,
"Second element of the measurement");
Element2.setScope(App::LinkScope::Global);
Element2.setAllowExternal(true);
ADD_PROPERTY_TYPE(Angle,(0.0) ,"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Angle,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Angle between the two elements");
Angle.setUnit(Base::Unit::Angle);
}
@@ -67,9 +78,8 @@ bool MeasureAngle::isValidSelection(const App::MeasureSelection& selection)
return false;
}
if (!(type == App::MeasureElementType::LINE ||
type == App::MeasureElementType::PLANE ||
type == App::MeasureElementType::LINESEGMENT)) {
if (!(type == App::MeasureElementType::LINE || type == App::MeasureElementType::PLANE
|| type == App::MeasureElementType::LINESEGMENT)) {
return false;
}
}
@@ -103,7 +113,8 @@ bool MeasureAngle::isPrioritizedSelection(const App::MeasureSelection& selection
}
void MeasureAngle::parseSelection(const App::MeasureSelection& selection) {
void MeasureAngle::parseSelection(const App::MeasureSelection& selection)
{
assert(selection.size() >= 2);
@@ -121,7 +132,8 @@ void MeasureAngle::parseSelection(const App::MeasureSelection& selection) {
}
bool MeasureAngle::getVec(App::DocumentObject& ob, std::string& subName, Base::Vector3d& vecOut) {
bool MeasureAngle::getVec(App::DocumentObject& ob, std::string& subName, Base::Vector3d& vecOut)
{
App::SubObjectT subject {&ob, subName.c_str()};
auto info = getMeasureInfo(subject);
if (!info || !info->valid) {
@@ -145,7 +157,8 @@ Base::Vector3d MeasureAngle::getLoc(App::DocumentObject& ob, std::string& subNam
return angleInfo->position;
}
gp_Vec MeasureAngle::vector1() {
gp_Vec MeasureAngle::vector1()
{
App::DocumentObject* ob = Element1.getValue();
std::vector<std::string> subs = Element1.getSubValues();
@@ -159,7 +172,8 @@ gp_Vec MeasureAngle::vector1() {
return gp_Vec(vec.x, vec.y, vec.z);
}
gp_Vec MeasureAngle::vector2() {
gp_Vec MeasureAngle::vector2()
{
App::DocumentObject* ob = Element2.getValue();
std::vector<std::string> subs = Element2.getSubValues();
@@ -172,7 +186,8 @@ gp_Vec MeasureAngle::vector2() {
return gp_Vec(vec.x, vec.y, vec.z);
}
gp_Vec MeasureAngle::location1() {
gp_Vec MeasureAngle::location1()
{
App::DocumentObject* ob = Element1.getValue();
std::vector<std::string> subs = Element1.getSubValues();
@@ -183,7 +198,8 @@ gp_Vec MeasureAngle::location1() {
auto temp = getLoc(*ob, subs.at(0));
return {temp.x, temp.y, temp.z};
}
gp_Vec MeasureAngle::location2() {
gp_Vec MeasureAngle::location2()
{
App::DocumentObject* ob = Element2.getValue();
std::vector<std::string> subs = Element2.getSubValues();
@@ -240,4 +256,3 @@ std::vector<App::DocumentObject*> MeasureAngle::getSubject() const
{
return {Element1.getValue()};
}

View File

@@ -56,7 +56,8 @@ public:
App::DocumentObjectExecReturn* execute() override;
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasureAngle";
}
@@ -64,8 +65,14 @@ public:
static bool isPrioritizedSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Element1", "Element2"};}
App::Property* getResultProp() override {return &this->Angle;}
std::vector<std::string> getInputProps() override
{
return {"Element1", "Element2"};
}
App::Property* getResultProp() override
{
return &this->Angle;
}
// Return the object we are measuring
std::vector<App::DocumentObject*> getSubject() const override;
@@ -83,7 +90,6 @@ public:
gp_Vec location2();
private:
void onChanged(const App::Property* prop) override;
};

View File

@@ -34,22 +34,28 @@ using namespace Measure;
PROPERTY_SOURCE(Measure::MeasureArea, Measure::MeasureBase)
MeasureArea::MeasureArea()
{
ADD_PROPERTY_TYPE(Elements,(nullptr), "Measurement", App::Prop_None, "Element to get the area from");
ADD_PROPERTY_TYPE(Elements,
(nullptr),
"Measurement",
App::Prop_None,
"Element to get the area from");
Elements.setScope(App::LinkScope::Global);
Elements.setAllowExternal(true);
ADD_PROPERTY_TYPE(Area,(0.0), "Measurement", App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Area,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Area of element");
}
MeasureArea::~MeasureArea() = default;
bool MeasureArea::isValidSelection(const App::MeasureSelection& selection){
bool MeasureArea::isValidSelection(const App::MeasureSelection& selection)
{
if (selection.empty()) {
return false;
@@ -70,7 +76,8 @@ bool MeasureArea::isValidSelection(const App::MeasureSelection& selection){
return true;
}
void MeasureArea::parseSelection(const App::MeasureSelection& selection) {
void MeasureArea::parseSelection(const App::MeasureSelection& selection)
{
// Set properties from selection, method is only invoked when isValid Selection returns true
std::vector<App::DocumentObject*> objects;
@@ -129,7 +136,8 @@ void MeasureArea::onChanged(const App::Property* prop)
}
Base::Placement MeasureArea::getPlacement() {
Base::Placement MeasureArea::getPlacement()
{
const std::vector<App::DocumentObject*>& objects = Elements.getValues();
const std::vector<std::string>& subElements = Elements.getSubValues();

View File

@@ -40,8 +40,6 @@ namespace Measure
{
class MeasureExport MeasureArea: public Measure::MeasureBaseExtendable<Part::MeasureAreaInfo>
{
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureArea);
@@ -57,15 +55,22 @@ public:
App::DocumentObjectExecReturn* execute() override;
void recalculateArea();
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasureArea";
}
static bool isValidSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Elements"};}
App::Property* getResultProp() override {return &this->Area;}
std::vector<std::string> getInputProps() override
{
return {"Elements"};
}
App::Property* getResultProp() override
{
return &this->Area;
}
// Return a placement for the viewprovider, just use the first element for now
Base::Placement getPlacement() override;
@@ -76,11 +81,9 @@ public:
private:
void onChanged(const App::Property* prop) override;
};
} // namespace Measure
#endif // MEASURE_MEASUREAREA_H

View File

@@ -35,9 +35,14 @@ using namespace Measure;
PROPERTY_SOURCE(Measure::MeasureBase, App::DocumentObject)
MeasureBase::MeasureBase() {
ADD_PROPERTY_TYPE(Placement, (Base::Placement()), nullptr, App::PropertyType(App::Prop_ReadOnly|App::Prop_Output|App::Prop_NoRecompute), "Visual placement of the measurement");
MeasureBase::MeasureBase()
{
ADD_PROPERTY_TYPE(
Placement,
(Base::Placement()),
nullptr,
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output | App::Prop_NoRecompute),
"Visual placement of the measurement");
}
@@ -50,7 +55,8 @@ PyObject *MeasureBase::getPyObject(void)
return Py::new_reference_to(PythonObject);
}
Py::Object MeasureBase::getProxyObject() const {
Py::Object MeasureBase::getProxyObject() const
{
Base::PyGILStateLocker lock;
App::Property* prop = this->getPropertyByName("Proxy");
if (!prop) {
@@ -59,7 +65,8 @@ Py::Object MeasureBase::getProxyObject() const {
return dynamic_cast<App::PropertyPythonObject*>(prop)->getValue();
};
std::vector<App::DocumentObject*> MeasureBase::getSubject() const {
std::vector<App::DocumentObject*> MeasureBase::getSubject() const
{
Base::PyGILStateLocker lock;
Py::Object proxy = getProxyObject();
@@ -71,7 +78,8 @@ std::vector<App::DocumentObject*> MeasureBase::getSubject() const {
Py::Object ret;
try {
ret = proxy.callMemberFunction("getSubject", args);
} catch (Py::Exception&) {
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
return {};
@@ -87,9 +95,8 @@ std::vector<App::DocumentObject*> MeasureBase::getSubject() const {
};
void MeasureBase::parseSelection(const App::MeasureSelection& selection) {
void MeasureBase::parseSelection(const App::MeasureSelection& selection)
{
Base::PyGILStateLocker lock;
Py::Object proxy = getProxyObject();
@@ -106,15 +113,16 @@ void MeasureBase::parseSelection(const App::MeasureSelection& selection) {
// Call the parseSelection method of the proxy object
try {
proxy.callMemberFunction("parseSelection", args);
} catch (Py::Exception&) {
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
}
}
std::vector<std::string> MeasureBase::getInputProps() {
std::vector<std::string> MeasureBase::getInputProps()
{
Base::PyGILStateLocker lock;
Py::Object proxy = getProxyObject();
@@ -125,7 +133,8 @@ std::vector<std::string> MeasureBase::getInputProps() {
Py::Object ret;
try {
ret = proxy.callMemberFunction("getInputProps");
} catch (Py::Exception&) {
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
return {};
@@ -142,8 +151,8 @@ std::vector<std::string> MeasureBase::getInputProps() {
}
QString MeasureBase::getResultString() {
QString MeasureBase::getResultString()
{
Py::Object proxy = getProxyObject();
Base::PyGILStateLocker lock;
@@ -156,7 +165,8 @@ QString MeasureBase::getResultString() {
Py::Object ret;
try {
ret = proxy.callMemberFunction("getResultString", args);
} catch (Py::Exception&) {
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
return QString();
@@ -177,25 +187,32 @@ QString MeasureBase::getResultString() {
return QString();
}
void MeasureBase::onDocumentRestored() {
void MeasureBase::onDocumentRestored()
{
// Force recompute the measurement
recompute();
}
Base::Placement MeasureBase::getPlacement() {
Base::Placement MeasureBase::getPlacement()
{
return this->Placement.getValue();
}
// Python Drawing feature ---------------------------------------------------------
namespace App {
namespace App
{
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(Measure::MeasurePython, Measure::MeasureBase)
template<> const char* Measure::MeasurePython::getViewProviderName(void) const {
template<>
const char* Measure::MeasurePython::getViewProviderName(void) const
{
return "MeasureGui::ViewProviderMeasure";
}
template<> PyObject* Measure::MeasurePython::getPyObject() {
template<>
PyObject* Measure::MeasurePython::getPyObject()
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new FeaturePythonPyT<Measure::MeasureBasePy>(this), true);
@@ -206,6 +223,4 @@ template<> PyObject* Measure::MeasurePython::getPyObject() {
// explicit template instantiation
template class MeasureExport FeaturePythonT<Measure::MeasureBase>;
}
} // namespace App

View File

@@ -68,7 +68,10 @@ public:
virtual QString getResultString();
virtual std::vector<std::string> getInputProps();
virtual App::Property* getResultProp() {return {};}
virtual App::Property* getResultProp()
{
return {};
}
virtual Base::Placement getPlacement();
// Return the objects that are measured
@@ -93,12 +96,13 @@ class MeasureExport MeasureBaseExtendable : public MeasureBase
public:
static void addGeometryHandler(const std::string& module, GeometryHandler callback) {
static void addGeometryHandler(const std::string& module, GeometryHandler callback)
{
_mGeometryHandlers[module] = callback;
}
static GeometryHandler getGeometryHandler(const std::string& module) {
static GeometryHandler getGeometryHandler(const std::string& module)
{
if (!hasGeometryHandler(module)) {
return {};
@@ -107,7 +111,8 @@ public:
return _mGeometryHandlers[module];
}
static Part::MeasureInfoPtr getMeasureInfo(App::SubObjectT& subObjT) {
static Part::MeasureInfoPtr getMeasureInfo(App::SubObjectT& subObjT)
{
// Resolve App::Link
App::DocumentObject* sub = subObjT.getSubObject();
@@ -122,23 +127,27 @@ public:
auto handler = getGeometryHandler(mod);
if (!handler) {
Base::Console().Log("MeasureBaseExtendable::getMeasureInfo: No geometry handler available for submitted element type");
Base::Console().Log("MeasureBaseExtendable::getMeasureInfo: No geometry handler "
"available for submitted element type");
return nullptr;
}
return handler(subObjT);
}
static void addGeometryHandlers(const std::vector<std::string>& modules, GeometryHandler callback){
// TODO: this will replace a callback with a later one. Should we check that there isn't already a
// handler defined for this module?
static void addGeometryHandlers(const std::vector<std::string>& modules,
GeometryHandler callback)
{
// TODO: this will replace a callback with a later one. Should we check that there isn't
// already a handler defined for this module?
for (auto& mod : modules) {
_mGeometryHandlers[mod] = callback;
}
}
static bool hasGeometryHandler(const std::string& module) {
static bool hasGeometryHandler(const std::string& module)
{
return (_mGeometryHandlers.count(module) > 0);
}
@@ -147,7 +156,6 @@ private:
};
} // namespace Measure

View File

@@ -39,37 +39,65 @@ PROPERTY_SOURCE(Measure::MeasureDistance, Measure::MeasureBase)
MeasureDistance::MeasureDistance()
{
ADD_PROPERTY_TYPE(Element1,(nullptr), "Measurement", App::Prop_None, "First element of the measurement");
ADD_PROPERTY_TYPE(Element1,
(nullptr),
"Measurement",
App::Prop_None,
"First element of the measurement");
Element1.setScope(App::LinkScope::Global);
Element1.setAllowExternal(true);
ADD_PROPERTY_TYPE(Element2,(nullptr), "Measurement", App::Prop_None, "Second element of the measurement");
ADD_PROPERTY_TYPE(Element2,
(nullptr),
"Measurement",
App::Prop_None,
"Second element of the measurement");
Element2.setScope(App::LinkScope::Global);
Element2.setAllowExternal(true);
ADD_PROPERTY_TYPE(Distance,(0.0) ,"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
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(DistanceX,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceX,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in X direction");
DistanceX.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(DistanceY,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceY,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in Y direction");
DistanceY.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(DistanceZ,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceZ,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in Z direction");
DistanceZ.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(Position1,(Base::Vector3d(0.0,0.0,0.0)),"Measurement", App::Prop_Hidden, "Position1");
ADD_PROPERTY_TYPE(Position2,(Base::Vector3d(0.0,1.0,0.0)),"Measurement", App::Prop_Hidden, "Position2");
ADD_PROPERTY_TYPE(Position1,
(Base::Vector3d(0.0, 0.0, 0.0)),
"Measurement",
App::Prop_Hidden,
"Position1");
ADD_PROPERTY_TYPE(Position2,
(Base::Vector3d(0.0, 1.0, 0.0)),
"Measurement",
App::Prop_Hidden,
"Position2");
}
MeasureDistance::~MeasureDistance() = default;
bool MeasureDistance::isValidSelection(const App::MeasureSelection& selection){
bool MeasureDistance::isValidSelection(const App::MeasureSelection& selection)
{
if (selection.size() != 2) {
return false;
@@ -82,23 +110,19 @@ bool MeasureDistance::isValidSelection(const App::MeasureSelection& selection){
return false;
}
if (
type != App::MeasureElementType::POINT &&
type != App::MeasureElementType::LINE &&
type != App::MeasureElementType::LINESEGMENT &&
type != App::MeasureElementType::CIRCLE &&
type != App::MeasureElementType::ARC &&
type != App::MeasureElementType::CURVE &&
type != App::MeasureElementType::PLANE &&
type != App::MeasureElementType::CYLINDER
) {
if (type != App::MeasureElementType::POINT && type != App::MeasureElementType::LINE
&& type != App::MeasureElementType::LINESEGMENT
&& type != App::MeasureElementType::CIRCLE && type != App::MeasureElementType::ARC
&& type != App::MeasureElementType::CURVE && type != App::MeasureElementType::PLANE
&& type != App::MeasureElementType::CYLINDER) {
return false;
}
}
return true;
}
bool MeasureDistance::isPrioritizedSelection(const App::MeasureSelection& selection) {
bool MeasureDistance::isPrioritizedSelection(const App::MeasureSelection& selection)
{
(void)selection;
@@ -111,7 +135,8 @@ bool MeasureDistance::isPrioritizedSelection(const App::MeasureSelection& select
}
void MeasureDistance::parseSelection(const App::MeasureSelection& selection) {
void MeasureDistance::parseSelection(const App::MeasureSelection& selection)
{
assert(selection.size() >= 2);
@@ -129,7 +154,8 @@ void MeasureDistance::parseSelection(const App::MeasureSelection& selection) {
}
bool MeasureDistance::getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape) {
bool MeasureDistance::getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape)
{
App::DocumentObject* ob = prop->getValue();
std::vector<std::string> subs = prop->getSubValues();
@@ -223,37 +249,58 @@ std::vector<App::DocumentObject*> MeasureDistance::getSubject() const
}
PROPERTY_SOURCE(Measure::MeasureDistanceDetached, Measure::MeasureBase)
MeasureDistanceDetached::MeasureDistanceDetached()
{
ADD_PROPERTY_TYPE(Distance,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
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(DistanceX,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceX,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in X direction");
DistanceX.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(DistanceY,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceY,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in Y direction");
DistanceY.setUnit(Base::Unit::Length);
ADD_PROPERTY_TYPE(DistanceZ,(0.0),"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(DistanceZ,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Distance in Z direction");
DistanceZ.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");
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){
bool MeasureDistanceDetached::isValidSelection(const App::MeasureSelection& selection)
{
return selection.size() == 2;
}
void MeasureDistanceDetached::parseSelection(const App::MeasureSelection& selection) {
void MeasureDistanceDetached::parseSelection(const App::MeasureSelection& selection)
{
auto sel1 = selection.at(0);
auto sel2 = selection.at(1);
@@ -297,7 +344,6 @@ std::vector<App::DocumentObject*> MeasureDistanceDetached::getSubject() const
}
Base::Type MeasureDistanceType::getClassTypeId()
{
return Base::Type::badType();
@@ -324,7 +370,6 @@ void* MeasureDistanceType::create()
Base::Type MeasureDistanceType::classTypeId = Base::Type::badType();
// Migrate old MeasureDistance Type
void MeasureDistanceDetached::handleChangedPropertyName(Base::XMLReader& reader,
const char* TypeName,

View File

@@ -51,7 +51,8 @@ private:
};
class MeasureExport MeasureDistance : public Measure::MeasureBaseExtendable<Part::MeasureDistanceInfo>
class MeasureExport MeasureDistance
: public Measure::MeasureBaseExtendable<Part::MeasureDistanceInfo>
{
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureDistance);
@@ -73,7 +74,8 @@ public:
App::DocumentObjectExecReturn* execute() override;
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasureDistance";
}
@@ -81,8 +83,14 @@ public:
static bool isPrioritizedSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Element1", "Element2"};}
App::Property* getResultProp() override {return &this->Distance;}
std::vector<std::string> getInputProps() override
{
return {"Element1", "Element2"};
}
App::Property* getResultProp() override
{
return &this->Distance;
}
bool getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape);
@@ -91,14 +99,10 @@ public:
private:
void onChanged(const App::Property* prop) override;
};
class MeasureExport MeasureDistanceDetached: public Measure::MeasureBase
{
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureDistanceDetached);
@@ -119,15 +123,22 @@ public:
App::DocumentObjectExecReturn* execute() override;
void recalculateDistance();
const char* getViewProviderName() const override {
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;}
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;
@@ -138,7 +149,6 @@ public:
private:
void onChanged(const App::Property* prop) override;
};

View File

@@ -36,22 +36,28 @@ using namespace Measure;
PROPERTY_SOURCE(Measure::MeasureLength, Measure::MeasureBase)
MeasureLength::MeasureLength()
{
ADD_PROPERTY_TYPE(Elements,(nullptr), "Measurement", App::Prop_None, "Elements to get the length from");
ADD_PROPERTY_TYPE(Elements,
(nullptr),
"Measurement",
App::Prop_None,
"Elements to get the length from");
Elements.setScope(App::LinkScope::Global);
Elements.setAllowExternal(true);
ADD_PROPERTY_TYPE(Length,(0.0) ,"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Length,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Length of selection");
}
MeasureLength::~MeasureLength() = default;
bool MeasureLength::isValidSelection(const App::MeasureSelection& selection){
bool MeasureLength::isValidSelection(const App::MeasureSelection& selection)
{
if (selection.empty()) {
return false;
@@ -72,7 +78,8 @@ bool MeasureLength::isValidSelection(const App::MeasureSelection& selection){
return true;
}
void MeasureLength::parseSelection(const App::MeasureSelection& selection) {
void MeasureLength::parseSelection(const App::MeasureSelection& selection)
{
// Set properties from selection, method is only invoked when isValid Selection returns true
std::vector<App::DocumentObject*> objects;
@@ -132,7 +139,8 @@ void MeasureLength::onChanged(const App::Property* prop)
}
Base::Placement MeasureLength::getPlacement() {
Base::Placement MeasureLength::getPlacement()
{
const std::vector<App::DocumentObject*>& objects = Elements.getValues();
const std::vector<std::string>& subElements = Elements.getSubValues();
@@ -157,4 +165,3 @@ std::vector<App::DocumentObject*> MeasureLength::getSubject() const
{
return Elements.getValues();
}

View File

@@ -52,15 +52,22 @@ public:
App::DocumentObjectExecReturn* execute() override;
void recalculateLength();
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasureLength";
}
static bool isValidSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Elements"};}
App::Property* getResultProp() override {return &this->Length;}
std::vector<std::string> getInputProps() override
{
return {"Elements"};
}
App::Property* getResultProp() override
{
return &this->Length;
}
// Return a placement for the viewprovider, just use the first element for now
Base::Placement getPlacement() override;
@@ -71,11 +78,9 @@ public:
private:
void onChanged(const App::Property* prop) override;
};
} // namespace Measure
#endif // MEASURE_MEASURELENGTH_H

View File

@@ -35,23 +35,29 @@ using namespace Measure;
PROPERTY_SOURCE(Measure::MeasurePosition, Measure::MeasureBase)
MeasurePosition::MeasurePosition()
{
ADD_PROPERTY_TYPE(Element,(nullptr), "Measurement", App::Prop_None, "Element to get the position from");
ADD_PROPERTY_TYPE(Element,
(nullptr),
"Measurement",
App::Prop_None,
"Element to get the position from");
Element.setScope(App::LinkScope::Global);
Element.setAllowExternal(true);
ADD_PROPERTY_TYPE(Position,(0.0, 0.0, 0.0), "Measurement", App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Position,
(0.0, 0.0, 0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"The absolute position");
}
MeasurePosition::~MeasurePosition() = default;
bool MeasurePosition::isValidSelection(const App::MeasureSelection& selection){
bool MeasurePosition::isValidSelection(const App::MeasureSelection& selection)
{
if (selection.empty() || selection.size() > 1) {
return false;
@@ -71,7 +77,8 @@ bool MeasurePosition::isValidSelection(const App::MeasureSelection& selection){
return true;
}
void MeasurePosition::parseSelection(const App::MeasureSelection& selection) {
void MeasurePosition::parseSelection(const App::MeasureSelection& selection)
{
// Set properties from selection, method is only invoked when isValid Selection returns true
for (auto element : selection) {
@@ -119,7 +126,8 @@ void MeasurePosition::onChanged(const App::Property* prop)
}
QString MeasurePosition::getResultString() {
QString MeasurePosition::getResultString()
{
App::Property* prop = this->getResultProp();
if (prop == nullptr) {
return {};
@@ -130,21 +138,22 @@ QString MeasurePosition::getResultString() {
int precision = 2;
QString text;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QTextStream(&text)
<< "X: " << QString::number(value.x, 'f', precision) << " " << unit << endl
QTextStream(&text) << "X: " << QString::number(value.x, 'f', precision) << " " << unit << endl
<< "Y: " << QString::number(value.y, 'f', precision) << " " << unit << endl
<< "Z: " << QString::number(value.z, 'f', precision) << " " << unit;
#else
QTextStream(&text)
<< "X: " << QString::number(value.x, 'f', precision) << " " << unit << Qt::endl
<< "Y: " << QString::number(value.y, 'f', precision) << " " << unit << Qt::endl
QTextStream(&text) << "X: " << QString::number(value.x, 'f', precision) << " " << unit
<< Qt::endl
<< "Y: " << QString::number(value.y, 'f', precision) << " " << unit
<< Qt::endl
<< "Z: " << QString::number(value.z, 'f', precision) << " " << unit;
#endif
return text;
}
Base::Placement MeasurePosition::getPlacement() {
Base::Placement MeasurePosition::getPlacement()
{
Base::Placement placement;
placement.setPosition(Position.getValue());
return placement;

View File

@@ -40,7 +40,8 @@ namespace Measure
{
class MeasureExport MeasurePosition : public Measure::MeasureBaseExtendable<Part::MeasurePositionInfo>
class MeasureExport MeasurePosition
: public Measure::MeasureBaseExtendable<Part::MeasurePositionInfo>
{
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasurePosition);
@@ -55,15 +56,22 @@ public:
App::DocumentObjectExecReturn* execute() override;
void recalculatePosition();
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasurePosition";
}
static bool isValidSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Element"};}
App::Property* getResultProp() override {return &this->Position;}
std::vector<std::string> getInputProps() override
{
return {"Element"};
}
App::Property* getResultProp() override
{
return &this->Position;
}
QString getResultString() override;
Base::Placement getPlacement() override;
@@ -72,7 +80,6 @@ public:
std::vector<App::DocumentObject*> getSubject() const override;
private:
void onChanged(const App::Property* prop) override;
};

View File

@@ -43,16 +43,21 @@ using namespace Measure;
PROPERTY_SOURCE(Measure::MeasureRadius, Measure::MeasureBase)
MeasureRadius::MeasureRadius()
{
ADD_PROPERTY_TYPE(Element,(nullptr), "Measurement", App::Prop_None, "Element to get the radius from");
ADD_PROPERTY_TYPE(Element,
(nullptr),
"Measurement",
App::Prop_None,
"Element to get the radius from");
Element.setScope(App::LinkScope::Global);
Element.setAllowExternal(true);
ADD_PROPERTY_TYPE(Radius,(0.0) ,"Measurement",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Radius,
(0.0),
"Measurement",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Radius of selection");
}
MeasureRadius::~MeasureRadius() = default;
@@ -60,7 +65,8 @@ MeasureRadius::~MeasureRadius() = default;
//! validate all the object+subelement pairs in the selection. Must be circle or arc
//! and have a geometry handler available. We only calculate radius if there is a
//! single valid item in the selection
bool MeasureRadius::isValidSelection(const App::MeasureSelection& selection){
bool MeasureRadius::isValidSelection(const App::MeasureSelection& selection)
{
if (selection.empty() || selection.size() > 1) {
// too few or too many selections
@@ -74,8 +80,7 @@ bool MeasureRadius::isValidSelection(const App::MeasureSelection& selection){
return false;
}
if (type != App::MeasureElementType::CIRCLE
&& type != App::MeasureElementType::ARC) {
if (type != App::MeasureElementType::CIRCLE && type != App::MeasureElementType::ARC) {
return false;
}
@@ -84,7 +89,8 @@ bool MeasureRadius::isValidSelection(const App::MeasureSelection& selection){
//! return true if the selection is particularly interesting to MeasureRadius.
//! In this case we claim circles and arcs.
bool MeasureRadius::isPrioritizedSelection(const App::MeasureSelection& selection) {
bool MeasureRadius::isPrioritizedSelection(const App::MeasureSelection& selection)
{
if (selection.size() != 1) {
return false;
}
@@ -92,8 +98,7 @@ bool MeasureRadius::isPrioritizedSelection(const App::MeasureSelection& selectio
auto element = selection.front();
auto type = App::MeasureManager::getMeasureElementType(element);
if (type == App::MeasureElementType::CIRCLE
|| type == App::MeasureElementType::ARC) {
if (type == App::MeasureElementType::CIRCLE || type == App::MeasureElementType::ARC) {
return true;
}
@@ -102,7 +107,8 @@ bool MeasureRadius::isPrioritizedSelection(const App::MeasureSelection& selectio
//! Set properties from first item in selection. assumes a valid selection.
void MeasureRadius::parseSelection(const App::MeasureSelection& selection) {
void MeasureRadius::parseSelection(const App::MeasureSelection& selection)
{
auto element = selection.front();
auto objT = element.object;
@@ -138,7 +144,8 @@ void MeasureRadius::onChanged(const App::Property* prop)
//! return a placement (location + orientation) for the first element
Base::Placement MeasureRadius::getPlacement() {
Base::Placement MeasureRadius::getPlacement()
{
auto loc = getMeasureInfoFirst()->pointOnCurve;
auto p = Base::Placement();
p.setPosition(loc);

View File

@@ -53,7 +53,8 @@ public:
App::PropertyDistance Radius;
App::DocumentObjectExecReturn* execute() override;
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "MeasureGui::ViewProviderMeasureRadius";
}
@@ -63,8 +64,14 @@ public:
static bool isPrioritizedSelection(const App::MeasureSelection& selection);
void parseSelection(const App::MeasureSelection& selection) override;
std::vector<std::string> getInputProps() override {return {"Element"};}
App::Property* getResultProp() override {return &this->Radius;}
std::vector<std::string> getInputProps() override
{
return {"Element"};
}
App::Property* getResultProp() override
{
return &this->Radius;
}
// Return a placement for the viewprovider, just use the first element for now
Base::Placement getPlacement() override;
@@ -78,13 +85,9 @@ public:
private:
void onChanged(const App::Property* prop) override;
Part::MeasureRadiusInfoPtr getMeasureInfoFirst() const;
};
} // namespace Measure
#endif // MEASURE_MEASURERADIUS_H

View File

@@ -146,13 +146,10 @@ MeasureType Measurement::findType()
}
switch (refSubShape.ShapeType()) {
case TopAbs_VERTEX:
{
case TopAbs_VERTEX: {
verts++;
}
break;
case TopAbs_EDGE:
{
} break;
case TopAbs_EDGE: {
edges++;
TopoDS_Edge edge = TopoDS::Edge(refSubShape);
BRepAdaptor_Curve sf(edge);
@@ -163,10 +160,8 @@ MeasureType Measurement::findType()
else if (sf.GetType() == GeomAbs_Circle) {
circles++;
}
}
break;
case TopAbs_FACE:
{
} break;
case TopAbs_FACE: {
faces++;
TopoDS_Face face = TopoDS::Face(refSubShape);
BRepAdaptor_Surface sf(face);
@@ -186,8 +181,7 @@ MeasureType Measurement::findType()
else if (sf.GetType() == GeomAbs_Torus) {
torus++;
}
}
break;
} break;
default:
break;
}
@@ -323,7 +317,6 @@ TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subNam
catch (...) {
throw Base::RuntimeError("Measurement: Unknown error retrieving shape");
}
}
// TODO:: add lengthX, lengthY (and lengthZ??) support
@@ -342,10 +335,9 @@ double Measurement::length() const
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
const std::vector<std::string>& subElements = References3D.getSubValues();
if(measureType == MeasureType::Points ||
measureType == MeasureType::PointToPoint ||
measureType == MeasureType::PointToEdge ||
measureType == MeasureType::PointToSurface) {
if (measureType == MeasureType::Points || measureType == MeasureType::PointToPoint
|| measureType == MeasureType::PointToEdge
|| measureType == MeasureType::PointToSurface) {
Base::Vector3d diff = this->delta();
result = diff.Length();
@@ -377,8 +369,9 @@ double Measurement::length() const
double u = curve.FirstParameter();
double v = curve.LastParameter();
double radius = curve.Circle().Radius();
if (u > v) // if arc is reversed
if (u > v) { // if arc is reversed
std::swap(u, v);
}
double range = v - u;
result += radius * range;
@@ -392,7 +385,8 @@ double Measurement::length() const
break;
}
default: {
throw Base::RuntimeError("Measurement - length - Curve type not currently handled");
throw Base::RuntimeError(
"Measurement - length - Curve type not currently handled");
}
} // end switch
} // end for
@@ -403,8 +397,8 @@ double Measurement::length() const
double Measurement::lineLineDistance() const
{
// We don't use delta() because BRepExtrema_DistShapeShape return minimum length between line segment.
// Here we get the nominal distance between the infinite lines.
// We don't use delta() because BRepExtrema_DistShapeShape return minimum length between line
// segment. Here we get the nominal distance between the infinite lines.
double distance = 0.0;
if (measureType != MeasureType::TwoParallelLines || References3D.getSize() != 2) {
@@ -452,7 +446,8 @@ double Measurement::lineLineDistance() const
return distance;
}
double Measurement::planePlaneDistance() const {
double Measurement::planePlaneDistance() const
{
if (measureType != MeasureType::TwoPlanes || References3D.getSize() != 2) {
return 0.0;
}
@@ -514,8 +509,7 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
BRepAdaptor_Curve curve1(TopoDS::Edge(shape1));
BRepAdaptor_Curve curve2(TopoDS::Edge(shape2));
if(curve1.GetType() == GeomAbs_Line &&
curve2.GetType() == GeomAbs_Line) {
if (curve1.GetType() == GeomAbs_Line && curve2.GetType() == GeomAbs_Line) {
gp_Pnt pnt1First = curve1.Value(curve1.FirstParameter());
gp_Dir dir1 = curve1.Line().Direction();
@@ -544,9 +538,8 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
TopoDS_Shape shape0 = getShape(objects.at(0), subElements.at(0).c_str());
TopoDS_Shape shape1 = getShape(objects.at(1), subElements.at(1).c_str());
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(2).c_str());
if (shape0.ShapeType() != TopAbs_VERTEX ||
shape1.ShapeType() != TopAbs_VERTEX ||
shape2.ShapeType() != TopAbs_VERTEX) {
if (shape0.ShapeType() != TopAbs_VERTEX || shape1.ShapeType() != TopAbs_VERTEX
|| shape2.ShapeType() != TopAbs_VERTEX) {
throw Base::RuntimeError("Measurement references for 3 point angle are not Vertex");
}
gp_Pnt gEnd0 = BRep_Tool::Pnt(TopoDS::Vertex(shape0));
@@ -581,7 +574,8 @@ double Measurement::radius() const
return (double)curve.Circle().Radius();
}
}
else if (measureType == MeasureType::Cylinder || measureType == MeasureType::Sphere || measureType == MeasureType::Torus) {
else if (measureType == MeasureType::Cylinder || measureType == MeasureType::Sphere
|| measureType == MeasureType::Torus) {
TopoDS_Shape shape = getShape(objects.at(0), subElements.at(0).c_str());
TopoDS_Face face = TopoDS::Face(shape);
@@ -629,7 +623,8 @@ Base::Vector3d Measurement::delta() const
return Base::Vector3d(diff.X(), diff.Y(), diff.Z());
}
}
else if(measureType == MeasureType::PointToEdge || measureType == MeasureType::PointToSurface) {
else if (measureType == MeasureType::PointToEdge
|| measureType == MeasureType::PointToSurface) {
// BrepExtema can calculate minimum distance between any set of topology sets.
if (numRefs == 2) {
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
@@ -639,7 +634,8 @@ Base::Vector3d Measurement::delta() const
if (extrema.IsDone()) {
// Found the nearest point between point and curve
// NOTE we will assume there is only 1 solution (cyclic topology will create multiple solutions.
// NOTE we will assume there is only 1 solution (cyclic topology will create
// multiple solutions.
gp_Pnt P1 = extrema.PointOnShape1(1);
gp_Pnt P2 = extrema.PointOnShape2(1);
gp_XYZ diff = P2.XYZ() - P1.XYZ();
@@ -669,13 +665,13 @@ Base::Vector3d Measurement::delta() const
BRepAdaptor_Curve curve2(TopoDS::Edge(shape2));
// Only permit line to line distance
if(curve1.GetType() == GeomAbs_Line &&
curve2.GetType() == GeomAbs_Line) {
if (curve1.GetType() == GeomAbs_Line && curve2.GetType() == GeomAbs_Line) {
BRepExtrema_DistShapeShape extrema(shape1, shape2);
if (extrema.IsDone()) {
// Found the nearest point between point and curve
// NOTE we will assume there is only 1 solution (cyclic topology will create multiple solutions.
// NOTE we will assume there is only 1 solution (cyclic topology will create
// multiple solutions.
gp_Pnt P1 = extrema.PointOnShape1(1);
gp_Pnt P2 = extrema.PointOnShape2(1);
gp_XYZ diff = P2.XYZ() - P1.XYZ();
@@ -778,13 +774,15 @@ Base::Vector3d Measurement::massCenter() const
}
else {
Base::Console().Error("Measurement::massCenter - measureType is not recognized\n");
// throw Base::ValueError("Measurement - massCenter - Invalid References3D Provided");
// throw Base::ValueError("Measurement - massCenter - Invalid References3D
// Provided");
}
}
return result;
}
bool Measurement::planesAreParallel() const {
bool Measurement::planesAreParallel() const
{
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
const std::vector<std::string>& subElements = References3D.getSubValues();
@@ -827,7 +825,8 @@ bool Measurement::planesAreParallel() const {
return normal1.IsParallel(normal2, Precision::Angular());
}
bool Measurement::linesAreParallel() const {
bool Measurement::linesAreParallel() const
{
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
const std::vector<std::string>& subElements = References3D.getSubValues();

View File

@@ -36,7 +36,8 @@
class TopoDS_Shape;
namespace Measure
{
enum class MeasureType {
enum class MeasureType
{
Volumes, // Measure the Volume(s)
Edges, // Measure the Edge(s)
Line, // One Line
@@ -58,10 +59,11 @@ namespace Measure
Invalid
};
class MeasureExport Measurement : public Base::BaseClass {
class MeasureExport Measurement: public Base::BaseClass
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
public:
App::PropertyLinkSubList References3D;
public:
@@ -92,7 +94,8 @@ public:
double radius() const;
// Calculates the angle between two edges
double angle(const Base::Vector3d &param = Base::Vector3d(0,0,0)) const; //param is never used???
double
angle(const Base::Vector3d& param = Base::Vector3d(0, 0, 0)) const; // param is never used???
// Calculate the center of mass
Base::Vector3d massCenter() const;
@@ -103,7 +106,10 @@ public:
// Calculate the area of selection
double area() const;
static Base::Vector3d toVector3d(const gp_Pnt gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const gp_Pnt gp)
{
return Base::Vector3d(gp.X(), gp.Y(), gp.Z());
}
bool planesAreParallel() const;
bool linesAreParallel() const;
@@ -117,7 +123,7 @@ private:
};
} //namespace measure
} // namespace Measure
#endif // MEASURE_MEASUREMENT_H

View File

@@ -58,8 +58,9 @@ PyObject* MeasurementPy::addReference3D(PyObject *args)
{
char* ObjectName;
char* SubName;
if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName,&SubName))
if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName, &SubName)) {
return nullptr;
}
// get the target object for the external link
App::DocumentObject* Obj = App::GetApplication().getActiveDocument()->getObject(ObjectName);
@@ -84,8 +85,9 @@ PyObject* MeasurementPy::addReference3D(PyObject *args)
PyObject* MeasurementPy::has3DReferences(PyObject* args)
{
PyObject* result = Py_False;
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
if (getMeasurementPtr()->has3DReferences()) {
result = Py_True;
@@ -97,8 +99,9 @@ PyObject* MeasurementPy::has3DReferences(PyObject *args)
PyObject* MeasurementPy::clear(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
this->getMeasurementPtr()->clear();
@@ -107,8 +110,9 @@ PyObject* MeasurementPy::clear(PyObject *args)
PyObject* MeasurementPy::delta(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Vector delta(this->getMeasurementPtr()->delta());
@@ -117,8 +121,9 @@ PyObject* MeasurementPy::delta(PyObject *args)
PyObject* MeasurementPy::length(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float length;
length = this->getMeasurementPtr()->length();
@@ -128,8 +133,9 @@ PyObject* MeasurementPy::length(PyObject *args)
PyObject* MeasurementPy::lineLineDistance(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float length;
length = this->getMeasurementPtr()->lineLineDistance();
@@ -139,8 +145,9 @@ PyObject* MeasurementPy::lineLineDistance(PyObject *args)
PyObject* MeasurementPy::planePlaneDistance(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float length;
length = this->getMeasurementPtr()->planePlaneDistance();
@@ -150,8 +157,9 @@ PyObject* MeasurementPy::planePlaneDistance(PyObject *args)
PyObject* MeasurementPy::volume(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float length;
length = this->getMeasurementPtr()->volume();
@@ -161,8 +169,9 @@ PyObject* MeasurementPy::volume(PyObject *args)
PyObject* MeasurementPy::area(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float length;
length = this->getMeasurementPtr()->area();
@@ -172,8 +181,9 @@ PyObject* MeasurementPy::area(PyObject *args)
PyObject* MeasurementPy::radius(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float radius;
radius = this->getMeasurementPtr()->radius();
@@ -183,8 +193,9 @@ PyObject* MeasurementPy::radius(PyObject *args)
PyObject* MeasurementPy::angle(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Float angle;
angle = this->getMeasurementPtr()->angle();
@@ -194,8 +205,9 @@ PyObject* MeasurementPy::angle(PyObject *args)
PyObject* MeasurementPy::com(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Py::Vector com(this->getMeasurementPtr()->massCenter());

View File

@@ -40,27 +40,33 @@ using namespace Measure;
//! Returns the Measure preference group
Base::Reference<ParameterGrp> Preferences::getPreferenceGroup(const char* Name)
{
return App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Measure")->GetGroup(Name);
return App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp/Preferences/Mod/Measure")
->GetGroup(Name);
}
App::Color Preferences::defaultLineColor()
{
App::Color fcColor;
fcColor.setPackedValue(getPreferenceGroup("Appearance")->GetUnsigned("DefaultLineColor", 0x3CF00000));
fcColor.setPackedValue(
getPreferenceGroup("Appearance")->GetUnsigned("DefaultLineColor", 0x3CF00000));
return fcColor;
}
App::Color Preferences::defaultTextColor()
{
App::Color fcColor;
fcColor.setPackedValue(getPreferenceGroup("Appearance")->GetUnsigned("DefaultTextColor", 0x00000000));
fcColor.setPackedValue(
getPreferenceGroup("Appearance")->GetUnsigned("DefaultTextColor", 0x00000000));
return fcColor;
}
App::Color Preferences::defaultTextBackgroundColor()
{
App::Color fcColor;
fcColor.setPackedValue(getPreferenceGroup("Appearance")->GetUnsigned("DefaultTextBackgroundColor", 0x3CF00000));
fcColor.setPackedValue(
getPreferenceGroup("Appearance")->GetUnsigned("DefaultTextBackgroundColor", 0x3CF00000));
return fcColor;
}

View File

@@ -53,4 +53,3 @@ public:
} // end namespace Measure
#endif

View File

@@ -93,6 +93,7 @@ PyMOD_INIT_FUNC(MeasureGui)
// instantiating the commands
CreateMeasureCommands();
// clang-format off
MeasureGui::DimensionLinear::initClass();
MeasureGui::ViewProviderMeasureGroup ::init();
@@ -105,9 +106,11 @@ PyMOD_INIT_FUNC(MeasureGui)
MeasureGui::ViewProviderMeasureLength ::init();
MeasureGui::ViewProviderMeasurePosition ::init();
MeasureGui::ViewProviderMeasureRadius ::init();
// clang-format on
// register preferences pages
new Gui::PrefPageProducer<MeasureGui::DlgPrefsMeasureAppearanceImp>(QT_TRANSLATE_NOOP("QObject", "Measure"));
new Gui::PrefPageProducer<MeasureGui::DlgPrefsMeasureAppearanceImp>(
QT_TRANSLATE_NOOP("QObject", "Measure"));
// Q_INIT_RESOURCE(Measure);

View File

@@ -99,4 +99,3 @@ fc_copy_sources(MeasureGui "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Mea
INSTALL(TARGETS MeasureGui DESTINATION ${CMAKE_INSTALL_LIBDIR})
INSTALL(FILES ${MeasureGuiIcon_SVG} DESTINATION "${CMAKE_INSTALL_DATADIR}/Mod/Measure/Resources/icons")

View File

@@ -60,7 +60,8 @@ void StdCmdMeasure::activated(int iMsg)
Gui::Control().showDialog(task);
}
bool StdCmdMeasure::isActive() {
bool StdCmdMeasure::isActive()
{
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc || doc->countObjectsOfType(App::GeoFeature::getClassTypeId()) == 0) {
return false;
@@ -68,18 +69,17 @@ bool StdCmdMeasure::isActive() {
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer *viewer =
dynamic_cast<Gui::View3DInventor *>(view)->getViewer();
Gui::View3DInventorViewer* viewer = dynamic_cast<Gui::View3DInventor*>(view)->getViewer();
return !viewer->isEditing();
}
return false;
}
void CreateMeasureCommands() {
void CreateMeasureCommands()
{
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
auto cmd = new StdCmdMeasure();
cmd->initAction();
rcCmdMgr.addCommand(cmd);
}

View File

@@ -68,4 +68,3 @@ void DlgPrefsMeasureAppearanceImp::changeEvent(QEvent *e)
}
#include <Mod/Measure/Gui/moc_DlgPrefsMeasureAppearanceImp.cpp>

View File

@@ -28,7 +28,8 @@
#include <Mod/Measure/MeasureGlobal.h>
namespace MeasureGui {
namespace MeasureGui
{
class Ui_DlgPrefsMeasureAppearanceImp;
@@ -52,4 +53,3 @@ private:
} // namespace MeasureGui
#endif // MeasureGui_DlgPrefsAppearanceImp_H

View File

@@ -94,4 +94,3 @@
#endif //_PreComp_
#endif

View File

@@ -103,8 +103,8 @@ void QuickMeasure::tryMeasureSelection()
bool QuickMeasure::canMeasureSelection(const Gui::SelectionChanges& msg) const
{
if (msg.Type == Gui::SelectionChanges::SetPreselect ||
msg.Type == Gui::SelectionChanges::RmvPreselect) {
if (msg.Type == Gui::SelectionChanges::SetPreselect
|| msg.Type == Gui::SelectionChanges::RmvPreselect) {
return false;
}
@@ -158,7 +158,8 @@ void QuickMeasure::printResult()
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()));
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);
@@ -168,7 +169,8 @@ void QuickMeasure::printResult()
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) {
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(), rad.getSafeUserString()));
@@ -184,7 +186,8 @@ void QuickMeasure::printResult()
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(), dist.getSafeUserString()));
print(tr("Angle: %1, Total length: %2")
.arg(angle.getSafeUserString(), dist.getSafeUserString()));
}
else if (mtype == MeasureType::Line) {
Base::Quantity dist(measurement->length(), Base::Unit::Length);

View File

@@ -32,11 +32,13 @@
class QTimer;
namespace Measure {
namespace Measure
{
class Measurement;
}
namespace MeasureGui {
namespace MeasureGui
{
class QuickMeasure: public QObject, Gui::SelectionObserver
{

View File

@@ -49,7 +49,10 @@ TaskMeasure::TaskMeasure()
qApp->installEventFilter(this);
this->setButtonPosition(TaskMeasure::South);
auto taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("umf-measurement"), tr("Measurement"), true, nullptr);
auto taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("umf-measurement"),
tr("Measurement"),
true,
nullptr);
// Create mode dropdown and add all registered measuretypes
modeSwitch = new QComboBox();
@@ -60,7 +63,10 @@ TaskMeasure::TaskMeasure()
}
// Connect dropdown's change signal to our onModeChange slot
connect(modeSwitch, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskMeasure::onModeChanged);
connect(modeSwitch,
qOverload<int>(&QComboBox::currentIndexChanged),
this,
&TaskMeasure::onModeChanged);
// Result widget
valueResult = new QLineEdit();
@@ -87,22 +93,25 @@ TaskMeasure::TaskMeasure()
// Set selection style
Gui::Selection().setSelectionStyle(Gui::SelectionSingleton::SelectionStyle::GreedySelection);
if(!App::GetApplication().getActiveTransaction())
if (!App::GetApplication().getActiveTransaction()) {
App::GetApplication().setActiveTransaction("Add Measurement");
}
// Call invoke method delayed, otherwise the dialog might not be fully initialized
QTimer::singleShot(0, this, &TaskMeasure::invoke);
}
TaskMeasure::~TaskMeasure() {
TaskMeasure::~TaskMeasure()
{
Gui::Selection().setSelectionStyle(Gui::SelectionSingleton::SelectionStyle::NormalSelection);
detachSelection();
qApp->removeEventFilter(this);
}
void TaskMeasure::modifyStandardButtons(QDialogButtonBox* box) {
void TaskMeasure::modifyStandardButtons(QDialogButtonBox* box)
{
QPushButton* btn = box->button(QDialogButtonBox::Apply);
btn->setText(tr("Save"));
@@ -120,7 +129,8 @@ void TaskMeasure::modifyStandardButtons(QDialogButtonBox* box) {
connect(btn, &QPushButton::released, this, &TaskMeasure::reset);
}
bool canAnnotate(Measure::MeasureBase* obj) {
bool canAnnotate(Measure::MeasureBase* obj)
{
if (obj == nullptr) {
// null object, can't annotate this
return false;
@@ -135,7 +145,8 @@ bool canAnnotate(Measure::MeasureBase* obj) {
return true;
}
void TaskMeasure::enableAnnotateButton(bool state) {
void TaskMeasure::enableAnnotateButton(bool state)
{
// if the task ui is not init yet we don't have a button box.
if (!this->buttonBox) {
return;
@@ -145,12 +156,14 @@ void TaskMeasure::enableAnnotateButton(bool state) {
btn->setEnabled(state);
}
void TaskMeasure::setMeasureObject(Measure::MeasureBase* obj) {
void TaskMeasure::setMeasureObject(Measure::MeasureBase* obj)
{
_mMeasureObject = obj;
}
void TaskMeasure::update() {
void TaskMeasure::update()
{
App::Document* doc = App::GetApplication().getActiveDocument();
// Reset selection if the selected object is not valid
@@ -166,7 +179,8 @@ void TaskMeasure::update() {
std::string mod = Base::Type::getModuleName(sub->getTypeId().getName());
if (!App::MeasureManager::hasMeasureHandler(mod.c_str())) {
Base::Console().Message("No measure handler available for geometry of module: %s\n", mod);
Base::Console().Message("No measure handler available for geometry of module: %s\n",
mod);
clearSelection();
return;
}
@@ -223,10 +237,12 @@ void TaskMeasure::update() {
auto pyMeasureClass = measureType->pythonClass;
// Create a MeasurePython instance
auto featurePython = doc->addObject("Measure::MeasurePython", measureType->label.c_str());
auto featurePython =
doc->addObject("Measure::MeasurePython", measureType->label.c_str());
setMeasureObject((Measure::MeasureBase*)featurePython);
// Create an instance of the pyMeasureClass, the classe's initializer sets the object as proxy
// Create an instance of the pyMeasureClass, the classe's initializer sets the object as
// proxy
Py::Tuple args(1);
args.setItem(0, Py::asObject(featurePython->getPyObject()));
PyObject* result = PyObject_CallObject(pyMeasureClass, args.ptr());
@@ -235,8 +251,8 @@ void TaskMeasure::update() {
else {
// Create measure object
setMeasureObject(
(Measure::MeasureBase*)doc->addObject(measureType->measureObject.c_str(), measureType->label.c_str())
);
(Measure::MeasureBase*)doc->addObject(measureType->measureObject.c_str(),
measureType->label.c_str()));
}
}
@@ -254,15 +270,16 @@ void TaskMeasure::update() {
// Get result
valueResult->setText(_mMeasureObject->getResultString());
}
void TaskMeasure::close() {
void TaskMeasure::close()
{
Control().closeDialog();
}
void ensureGroup(Measure::MeasureBase* measurement) {
void ensureGroup(Measure::MeasureBase* measurement)
{
// Ensure measurement object is part of the measurements group
const char* measurementGroupName = "Measurements";
@@ -273,7 +290,10 @@ void ensureGroup(Measure::MeasureBase* measurement) {
App::Document* doc = App::GetApplication().getActiveDocument();
App::DocumentObject* obj = doc->getObject(measurementGroupName);
if (!obj || !obj->isValid()) {
obj = doc->addObject("App::DocumentObjectGroup", measurementGroupName, true, "MeasureGui::ViewProviderMeasureGroup");
obj = doc->addObject("App::DocumentObjectGroup",
measurementGroupName,
true,
"MeasureGui::ViewProviderMeasureGroup");
}
auto group = static_cast<App::DocumentObjectGroup*>(obj);
@@ -282,11 +302,13 @@ void ensureGroup(Measure::MeasureBase* measurement) {
// Runs after the dialog is created
void TaskMeasure::invoke() {
void TaskMeasure::invoke()
{
update();
}
bool TaskMeasure::apply() {
bool TaskMeasure::apply()
{
ensureGroup(_mMeasureObject);
_mMeasureObject = nullptr;
reset();
@@ -297,7 +319,8 @@ bool TaskMeasure::apply() {
return false;
}
bool TaskMeasure::reject() {
bool TaskMeasure::reject()
{
removeObject();
close();
@@ -306,7 +329,8 @@ bool TaskMeasure::reject() {
return false;
}
void TaskMeasure::reset() {
void TaskMeasure::reset()
{
// Reset tool state
this->clearSelection();
@@ -318,7 +342,8 @@ void TaskMeasure::reset() {
}
void TaskMeasure::removeObject() {
void TaskMeasure::removeObject()
{
if (_mMeasureObject == nullptr) {
return;
}
@@ -329,11 +354,13 @@ void TaskMeasure::removeObject() {
setMeasureObject(nullptr);
}
bool TaskMeasure::hasSelection() {
bool TaskMeasure::hasSelection()
{
return !Gui::Selection().getSelection().empty();
}
void TaskMeasure::clearSelection() {
void TaskMeasure::clearSelection()
{
Gui::Selection().clearSelection();
}
@@ -341,7 +368,8 @@ void TaskMeasure::onSelectionChanged(const Gui::SelectionChanges& msg)
{
// Skip non-relevant events
if (msg.Type != SelectionChanges::AddSelection && msg.Type != SelectionChanges::RmvSelection
&& msg.Type != SelectionChanges::SetSelection && msg.Type != SelectionChanges::ClrSelection) {
&& msg.Type != SelectionChanges::SetSelection
&& msg.Type != SelectionChanges::ClrSelection) {
return;
}
@@ -349,7 +377,8 @@ void TaskMeasure::onSelectionChanged(const Gui::SelectionChanges& msg)
update();
}
bool TaskMeasure::eventFilter(QObject* obj, QEvent* event) {
bool TaskMeasure::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
auto keyEvent = static_cast<QKeyEvent*>(event);
@@ -358,7 +387,8 @@ bool TaskMeasure::eventFilter(QObject* obj, QEvent* event) {
if (this->hasSelection()) {
this->reset();
} else {
}
else {
this->reject();
}
@@ -374,12 +404,14 @@ bool TaskMeasure::eventFilter(QObject* obj, QEvent* event) {
return TaskDialog::eventFilter(obj, event);
}
void TaskMeasure::onModeChanged(int index) {
void TaskMeasure::onModeChanged(int index)
{
explicitMode = (index != 0);
this->update();
}
void TaskMeasure::setModeSilent(App::MeasureType* mode) {
void TaskMeasure::setModeSilent(App::MeasureType* mode)
{
modeSwitch->blockSignals(true);
if (mode == nullptr) {
@@ -392,7 +424,8 @@ void TaskMeasure::setModeSilent(App::MeasureType* mode) {
}
// Get explicitly set measure type from the mode switch
App::MeasureType* TaskMeasure::getMeasureType() {
App::MeasureType* TaskMeasure::getMeasureType()
{
for (App::MeasureType* mType : App::MeasureManager::getMeasureTypes()) {
if (mType->label.c_str() == modeSwitch->currentText().toLatin1()) {
return mType;

View File

@@ -36,16 +36,19 @@
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
namespace Gui {
namespace Gui
{
class TaskMeasure : public TaskView::TaskDialog, public Gui::SelectionObserver {
class TaskMeasure: public TaskView::TaskDialog, public Gui::SelectionObserver
{
public:
TaskMeasure();
~TaskMeasure() override;
void modifyStandardButtons(QDialogButtonBox* box) override;
QDialogButtonBox::StandardButtons getStandardButtons() const override {
QDialogButtonBox::StandardButtons getStandardButtons() const override
{
return QDialogButtonBox::Apply | QDialogButtonBox::Abort | QDialogButtonBox::Reset;
}
@@ -80,7 +83,6 @@ private:
// Stores if the mode is explicitly set by the user or implicitly through the selection
bool explicitMode = false;
};
} // namespace Gui

View File

@@ -80,13 +80,15 @@
using namespace MeasureGui;
using namespace Measure;
gp_Lin getLine(gp_Vec& vec, gp_Vec& origin) {
gp_Lin getLine(gp_Vec& vec, gp_Vec& origin)
{
gp_Pnt tempOrigin;
tempOrigin.SetXYZ(origin.XYZ());
return gp_Lin(tempOrigin, gp_Dir(vec));
}
SbMatrix ViewProviderMeasureAngle::getMatrix() {
SbMatrix ViewProviderMeasureAngle::getMatrix()
{
// Code ported from src/Mod/Part/Gui/TaskDimension.cpp
if (pcObject == nullptr) {
@@ -125,8 +127,7 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
gp_Pnt tempPoint(loc1.XYZ());
GeomAPI_ProjectPointOnCurve projection(tempPoint, heapLine2);
if (projection.NbPoints() < 1)
{
if (projection.NbPoints() < 1) {
throw Base::RuntimeError("parallel vectors: couldn't project onto line");
}
gp_Vec newPoint2;
@@ -134,8 +135,9 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
// if points are colinear, projection doesn't work and returns the same point.
// In this case we just use the original point.
if ((newPoint2 - loc1).Magnitude() < Precision::Confusion())
if ((newPoint2 - loc1).Magnitude() < Precision::Confusion()) {
newPoint2 = loc2;
}
// now get midpoint between for dim origin.
gp_Vec point1 = loc1;
@@ -147,48 +149,60 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
gp_Vec origin = point1 + midPointProjection;
// yaxis should be the same as vector1, but doing this to eliminate any potential slop from
//using precision::angular. If lines are colinear and we have no plane, we can't establish zAxis from crossing.
//we just the absolute axis.
// using precision::angular. If lines are colinear and we have no plane, we can't establish
// zAxis from crossing. we just the absolute axis.
gp_Vec xAxis = (point1 - origin).Normalized();
gp_Vec zAxis;
if (xAxis.IsParallel(vector1, Precision::Angular())) {
if (!xAxis.IsParallel(gp_Vec(0.0, 0.0, 1.0), Precision::Angular()))
if (!xAxis.IsParallel(gp_Vec(0.0, 0.0, 1.0), Precision::Angular())) {
zAxis = gp_Vec(0.0, 0.0, 1.0);
else
}
else {
zAxis = gp_Vec(0.0, 1.0, 0.0);
}
else
}
else {
zAxis = xAxis.Crossed(vector1).Normalized();
}
gp_Vec yAxis = zAxis.Crossed(xAxis).Normalized();
zAxis = xAxis.Crossed(yAxis).Normalized();
dimSys = SbMatrix
(
xAxis.X(), yAxis.X(), zAxis.X(), origin.X(),
xAxis.Y(), yAxis.Y(), zAxis.Y(), origin.Y(),
xAxis.Z(), yAxis.Z(), zAxis.Z(), origin.Z(),
0.0, 0.0, 0.0, 1.0
);
dimSys = SbMatrix(xAxis.X(),
yAxis.X(),
zAxis.X(),
origin.X(),
xAxis.Y(),
yAxis.Y(),
zAxis.Y(),
origin.Y(),
xAxis.Z(),
yAxis.Z(),
zAxis.Z(),
origin.Z(),
0.0,
0.0,
0.0,
1.0);
dimSys = dimSys.transpose();
radius = midPointProjection.Magnitude();
} else {
}
else {
Handle(Geom_Curve) heapLine1 = new Geom_Line(lin1);
Handle(Geom_Curve) heapLine2 = new Geom_Line(lin2);
GeomAPI_ExtremaCurveCurve extrema(heapLine1, heapLine2);
if (extrema.NbExtrema() < 1)
{
if (extrema.NbExtrema() < 1) {
throw Base::RuntimeError("couldn't get extrema");
}
gp_Pnt extremaPoint1, extremaPoint2, dimensionOriginPoint;
extrema.Points(1, extremaPoint1, extremaPoint2);
if (extremaPoint1.Distance(extremaPoint2) < Precision::Confusion())
if (extremaPoint1.Distance(extremaPoint2) < Precision::Confusion()) {
dimensionOriginPoint = extremaPoint1;
else
{
}
else {
// find halfway point in between extrema points for dimension origin.
gp_Vec vec1(extremaPoint1.XYZ());
gp_Vec vec2(extremaPoint2.XYZ());
@@ -204,8 +218,7 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
gp_Vec extrema2Vector(extremaPoint2.XYZ());
radius = (loc1 - originVector).Magnitude();
double legOne = (extrema2Vector - originVector).Magnitude();
if (legOne > Precision::Confusion())
{
if (legOne > Precision::Confusion()) {
double legTwo = sqrt(pow(radius, 2) - pow(legOne, 2));
gp_Vec projectionVector(vector2);
projectionVector.Normalize();
@@ -222,13 +235,22 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
gp_Vec zAxis = (xAxis.Crossed(fakeYAxis)).Normalized();
gp_Vec yAxis = zAxis.Crossed(xAxis).Normalized();
dimSys = SbMatrix
(
xAxis.X(), yAxis.X(), zAxis.X(), dimensionOriginPoint.X(),
xAxis.Y(), yAxis.Y(), zAxis.Y(), dimensionOriginPoint.Y(),
xAxis.Z(), yAxis.Z(), zAxis.Z(), dimensionOriginPoint.Z(),
0.0, 0.0, 0.0, 1.0
);
dimSys = SbMatrix(xAxis.X(),
yAxis.X(),
zAxis.X(),
dimensionOriginPoint.X(),
xAxis.Y(),
yAxis.Y(),
zAxis.Y(),
dimensionOriginPoint.Y(),
xAxis.Z(),
yAxis.Z(),
zAxis.Z(),
dimensionOriginPoint.Z(),
0.0,
0.0,
0.0,
1.0);
dimSys = dimSys.transpose();
}
@@ -237,7 +259,6 @@ SbMatrix ViewProviderMeasureAngle::getMatrix() {
}
PROPERTY_SOURCE(MeasureGui::ViewProviderMeasureAngle, MeasureGui::ViewProviderMeasureBase)
@@ -269,7 +290,8 @@ ViewProviderMeasureAngle::ViewProviderMeasureAngle()
auto engineAngle = new SoCalculator();
engineAngle->A.connectFrom(&arcEngine->midpoint);
engineAngle->B.connectFrom(&pLabelTranslation->translation);
engineAngle->expression.setValue("tA=normalize(A); tB=normalize(B); oa=atan2(tB[1], tB[0])-atan2(tA[1], tA[0])");
engineAngle->expression.setValue(
"tA=normalize(A); tB=normalize(B); oa=atan2(tB[1], tB[0])-atan2(tA[1], tA[0])");
Gui::ArcEngine* arcEngineSecondary = new Gui::ArcEngine();
arcEngineSecondary->radius.connectFrom(&calculatorRadius->oa);
@@ -310,9 +332,10 @@ void ViewProviderMeasureAngle::redrawAnnotation()
try {
SbMatrix matrix = getMatrix();
pcTransform->setMatrix(matrix);
} catch (const Base::Exception& e) {
Base::Console().Error("Error in ViewProviderMeasureAngle::redrawAnnotation: %s\n", e.what());
}
catch (const Base::Exception& e) {
Base::Console().Error("Error in ViewProviderMeasureAngle::redrawAnnotation: %s\n",
e.what());
return;
}
@@ -332,8 +355,8 @@ Measure::MeasureAngle* ViewProviderMeasureAngle::getMeasureAngle()
}
void ViewProviderMeasureAngle::positionAnno(const Measure::MeasureBase* measureObject) {
void ViewProviderMeasureAngle::positionAnno(const Measure::MeasureBase* measureObject)
{
(void)measureObject;
setLabelTranslation(SbVec3f(0, 0.1 * getViewScale(), 0));
}

View File

@@ -69,5 +69,4 @@ private:
} // namespace MeasureGui
#endif // GUI_VIEWPROVIDERMEASUREANGLE_H

View File

@@ -69,7 +69,6 @@ QIcon ViewProviderMeasureGroup::getIcon() const
}
// NOLINTBEGIN
PROPERTY_SOURCE(MeasureGui::ViewProviderMeasureBase, Gui::ViewProviderDocumentObject)
// NOLINTEND
@@ -78,10 +77,26 @@ ViewProviderMeasureBase::ViewProviderMeasureBase()
{
static const char* agroup = "Appearance";
// NOLINTBEGIN
ADD_PROPERTY_TYPE(TextColor, (Preferences::defaultTextColor()), agroup, App::Prop_None, "Color for the measurement text");
ADD_PROPERTY_TYPE(TextBackgroundColor, (Preferences::defaultTextBackgroundColor()), agroup, App::Prop_None, "Color for the measurement text background");
ADD_PROPERTY_TYPE(LineColor, (Preferences::defaultLineColor()), agroup, App::Prop_None, "Color for the measurement lines");
ADD_PROPERTY_TYPE(FontSize, (Preferences::defaultFontSize()), agroup, App::Prop_None, "Size of measurement text");
ADD_PROPERTY_TYPE(TextColor,
(Preferences::defaultTextColor()),
agroup,
App::Prop_None,
"Color for the measurement text");
ADD_PROPERTY_TYPE(TextBackgroundColor,
(Preferences::defaultTextBackgroundColor()),
agroup,
App::Prop_None,
"Color for the measurement text background");
ADD_PROPERTY_TYPE(LineColor,
(Preferences::defaultLineColor()),
agroup,
App::Prop_None,
"Color for the measurement lines");
ADD_PROPERTY_TYPE(FontSize,
(Preferences::defaultFontSize()),
agroup,
App::Prop_None,
"Size of measurement text");
// NOLINTEND
pGlobalSeparator = new SoSeparator();
@@ -168,12 +183,12 @@ ViewProviderMeasureBase::ViewProviderMeasureBase()
dragger->setPart("yAxisFeedback", NULL);
// end setupSceneGraph
// these touches cause onChanged to run which then updates pLabel and pColor with the initial values
// these touches cause onChanged to run which then updates pLabel and pColor with the initial
// values
TextColor.touch();
TextBackgroundColor.touch();
FontSize.touch();
LineColor.touch();
}
ViewProviderMeasureBase::~ViewProviderMeasureBase()
@@ -207,7 +222,8 @@ void ViewProviderMeasureBase::setDisplayMode(const char* ModeName)
}
void ViewProviderMeasureBase::finishRestoring() {
void ViewProviderMeasureBase::finishRestoring()
{
// Force measurement visibility when loading a document
show();
}
@@ -234,16 +250,19 @@ void ViewProviderMeasureBase::onChanged(const App::Property* prop)
ViewProviderDocumentObject::onChanged(prop);
}
void ViewProviderMeasureBase::draggerChangedCallback(void *data, SoDragger *) {
void ViewProviderMeasureBase::draggerChangedCallback(void* data, SoDragger*)
{
auto me = static_cast<ViewProviderMeasureBase*>(data);
me->onLabelMoved();
}
void ViewProviderMeasureBase::setLabelValue(const Base::Quantity& value) {
void ViewProviderMeasureBase::setLabelValue(const Base::Quantity& value)
{
pLabel->string.setValue(value.getUserString().toUtf8().constData());
}
void ViewProviderMeasureBase::setLabelValue(const QString& value) {
void ViewProviderMeasureBase::setLabelValue(const QString& value)
{
auto lines = value.split(QString::fromLatin1("\n"));
int i = 0;
@@ -253,41 +272,48 @@ void ViewProviderMeasureBase::setLabelValue(const QString& value) {
}
}
void ViewProviderMeasureBase::setLabelTranslation(const SbVec3f& position) {
void ViewProviderMeasureBase::setLabelTranslation(const SbVec3f& position)
{
// Set the dragger translation to keep it in sync with pLabelTranslation
pDragger->translation.setValue(position);
}
SoPickStyle* ViewProviderMeasureBase::getSoPickStyle() {
SoPickStyle* ViewProviderMeasureBase::getSoPickStyle()
{
auto ps = new SoPickStyle();
ps->style = SoPickStyle::UNPICKABLE;
return ps;
}
SoDrawStyle* ViewProviderMeasureBase::getSoLineStylePrimary() {
SoDrawStyle* ViewProviderMeasureBase::getSoLineStylePrimary()
{
auto style = new SoDrawStyle();
style->lineWidth = 2.0f;
return style;
}
SoDrawStyle* ViewProviderMeasureBase::getSoLineStyleSecondary() {
SoDrawStyle* ViewProviderMeasureBase::getSoLineStyleSecondary()
{
auto style = new SoDrawStyle();
style->lineWidth = 1.0f;
return style;
}
SoSeparator* ViewProviderMeasureBase::getSoSeparatorText() {
SoSeparator* ViewProviderMeasureBase::getSoSeparatorText()
{
return pTextSeparator;
}
void ViewProviderMeasureBase::positionAnno(const Measure::MeasureBase* measureObject) {
void ViewProviderMeasureBase::positionAnno(const Measure::MeasureBase* measureObject)
{
(void)measureObject;
}
void ViewProviderMeasureBase::updateIcon() {
void ViewProviderMeasureBase::updateIcon()
{
// This assumes the icons main color is black
Gui::ColorMap colorMap {
@@ -320,7 +346,8 @@ void ViewProviderMeasureBase::updateData(const App::Property* prop)
// Check if one of the input properties has been changed
auto inputProps = obj->getInputProps();
if (std::find(inputProps.begin(), inputProps.end(), std::string(prop->getName())) != inputProps.end()) {
if (std::find(inputProps.begin(), inputProps.end(), std::string(prop->getName()))
!= inputProps.end()) {
doUpdate = true;
// Add connections to be notified when the measured objects are changed
@@ -365,7 +392,10 @@ void ViewProviderMeasureBase::connectToSubject(App::DocumentObject* subject)
}
// NOLINTBEGIN
auto bndVisibility = std::bind(&ViewProviderMeasureBase::onSubjectVisibilityChanged, this, std::placeholders::_1, std::placeholders::_2);
auto bndVisibility = std::bind(&ViewProviderMeasureBase::onSubjectVisibilityChanged,
this,
std::placeholders::_1,
std::placeholders::_2);
// NOLINTEND
_mVisibilityChangedConnection = subject->signalChanged.connect(bndVisibility);
}
@@ -386,7 +416,8 @@ void ViewProviderMeasureBase::connectToSubject(std::vector<App::DocumentObject*>
//! retrieve the feature
Measure::MeasureBase* ViewProviderMeasureBase::getMeasureObject()
{
// Note: Cast to MeasurePropertyBase once we use it to provide the needed values e.g. basePosition textPosition etc.
// Note: Cast to MeasurePropertyBase once we use it to provide the needed values e.g.
// basePosition textPosition etc.
auto feature = dynamic_cast<Measure::MeasureBase*>(pcObject);
if (!feature) {
throw Base::RuntimeError("Feature not found for ViewProviderMeasureBase");
@@ -395,32 +426,38 @@ Measure::MeasureBase* ViewProviderMeasureBase::getMeasureObject()
}
//! calculate a good direction from the elements being measured to the annotation text based on the layout
//! of the elements and relationship with the cardinal axes and the view direction. elementDirection
//! is expected to be a normalized vector.
//! an example of an elementDirection would be the vector from the start of a line to the end.
Base::Vector3d ViewProviderMeasureBase::getTextDirection(Base::Vector3d elementDirection, double tolerance)
//! calculate a good direction from the elements being measured to the annotation text based on the
//! layout of the elements and relationship with the cardinal axes and the view direction.
//! elementDirection is expected to be a normalized vector. an example of an elementDirection would
//! be the vector from the start of a line to the end.
Base::Vector3d ViewProviderMeasureBase::getTextDirection(Base::Vector3d elementDirection,
double tolerance)
{
// TODO: this can fail if the active view is not a 3d view (spreadsheet, techdraw page) and something causes a measure to try to update
// we need to search through the mdi views for a 3d view and take the direction from it (or decide that if the active view is not 3d,
// assume we are looking from the front).
// TODO: this can fail if the active view is not a 3d view (spreadsheet, techdraw page) and
// something causes a measure to try to update we need to search through the mdi views for a 3d
// view and take the direction from it (or decide that if the active view is not 3d, assume we
// are looking from the front).
Base::Vector3d viewDirection;
Base::Vector3d upDirection;
Gui::View3DInventor* view = nullptr;
try {
view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
} catch (const Base::RuntimeError&) {
Base::Console().Log("ViewProviderMeasureBase::getTextDirection: Could not get active view\n");
}
catch (const Base::RuntimeError&) {
Base::Console().Log(
"ViewProviderMeasureBase::getTextDirection: Could not get active view\n");
}
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewDirection = toVector3d(viewer->getViewDirection()).Normalize();
upDirection = toVector3d(viewer->getUpDirection()).Normalize();
// Measure doesn't work with this kind of active view. Might be dependency graph, might be TechDraw, or ????
// Measure doesn't work with this kind of active view. Might be dependency graph, might be
// TechDraw, or ????
// throw Base::RuntimeError("Measure doesn't work with this kind of active view.");
} else {
}
else {
viewDirection = Base::Vector3d(0.0, 1.0, 0.0);
upDirection = Base::Vector3d(0.0, 0.0, 1.0);
}
@@ -435,14 +472,15 @@ Gui::View3DInventor* view = nullptr;
}
//! true if the subject of this measurement is visible. For Measures that have multiple object subject,
//! all of the subjects must be visible.
//! true if the subject of this measurement is visible. For Measures that have multiple object
//! subject, all of the subjects must be visible.
bool ViewProviderMeasureBase::isSubjectVisible()
{
Gui::Document* guiDoc = nullptr;
try {
guiDoc = this->getDocument();
} catch (const Base::RuntimeError&) {
}
catch (const Base::RuntimeError&) {
Base::Console().Log("ViewProviderMeasureBase::isSubjectVisible: Could not get document\n");
return false;
}
@@ -469,9 +507,10 @@ bool ViewProviderMeasureBase::isSubjectVisible()
}
//! gets called when the subject object issues a signalChanged (ie a property change). We are only interested in the subject's
//! Visibility property
void ViewProviderMeasureBase::onSubjectVisibilityChanged(const App::DocumentObject& docObj, const App::Property& prop)
//! gets called when the subject object issues a signalChanged (ie a property change). We are only
//! interested in the subject's Visibility property
void ViewProviderMeasureBase::onSubjectVisibilityChanged(const App::DocumentObject& docObj,
const App::Property& prop)
{
if (docObj.isRemoving()) {
return;
@@ -482,15 +521,18 @@ void ViewProviderMeasureBase::onSubjectVisibilityChanged(const App::DocumentObje
if (!docObj.Visibility.getValue()) {
// show ourselves only if subject is visible
setVisible(false);
} else {
// here, we don't know if we should be visible or not, so we have to check the whole subject
}
else {
// here, we don't know if we should be visible or not, so we have to check the whole
// subject
setVisible(isSubjectVisible());
}
}
}
float ViewProviderMeasureBase::getViewScale() {
float ViewProviderMeasureBase::getViewScale()
{
float scale = 1.0;
Gui::View3DInventor* view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
@@ -501,8 +543,9 @@ float ViewProviderMeasureBase::getViewScale() {
Gui::View3DInventorViewer* viewer = view->getViewer();
SoCamera* const camera = viewer->getSoRenderManager()->getCamera();
if (!camera)
if (!camera) {
return false;
}
SbViewVolume volume(camera->getViewVolume());
SbVec3f center(volume.getSightPoint(camera->focalDistance.getValue()));
@@ -511,12 +554,12 @@ float ViewProviderMeasureBase::getViewScale() {
}
// NOLINTBEGIN
PROPERTY_SOURCE(MeasureGui::ViewProviderMeasure, MeasureGui::ViewProviderMeasureBase)
// NOLINTEND
//! the general purpose view provider. handles area, length, etc - any measure without a specialized VP
//! the general purpose view provider. handles area, length, etc - any measure without a
//! specialized VP
ViewProviderMeasure::ViewProviderMeasure()
{
sPixmap = "umf-measurement";
@@ -527,10 +570,7 @@ ViewProviderMeasure::ViewProviderMeasure()
// indexes used to create the edges
// this makes a line from verts[0] to verts[1]
static const int32_t lines[lineCount] =
{
0,1,-1
};
static const int32_t lines[lineCount] = {0, 1, -1};
pCoords = new SoCoordinate3();
pCoords->ref();
@@ -553,7 +593,8 @@ ViewProviderMeasure::ViewProviderMeasure()
lineSep->addChild(pCoords);
lineSep->addChild(pLines);
auto points = new SoMarkerSet();
points->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex("CROSS",
points->markerIndex =
Gui::Inventor::MarkerBitmaps::getMarkerIndex("CROSS",
Gui::ViewParams::instance()->getMarkerSize());
points->numPoints = 1;
lineSep->addChild(points);
@@ -562,8 +603,10 @@ ViewProviderMeasure::ViewProviderMeasure()
Gui::View3DInventor* view = nullptr;
try {
view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
} catch (const Base::RuntimeError& ) {
Base::Console().Log("ViewProviderMeasure::ViewProviderMeasure: Could not get active view\n");
}
catch (const Base::RuntimeError&) {
Base::Console().Log(
"ViewProviderMeasure::ViewProviderMeasure: Could not get active view\n");
}
if (view) {
@@ -572,8 +615,6 @@ ViewProviderMeasure::ViewProviderMeasure()
auto cam = renderManager->getCamera();
pDraggerOrientation->rotation.connectFrom(&cam->orientation);
}
}
ViewProviderMeasure::~ViewProviderMeasure()
@@ -582,7 +623,8 @@ ViewProviderMeasure::~ViewProviderMeasure()
pLines->unref();
}
void ViewProviderMeasure::positionAnno(const Measure::MeasureBase* measureObject) {
void ViewProviderMeasure::positionAnno(const Measure::MeasureBase* measureObject)
{
(void)measureObject;
// Initialize the text position
@@ -593,7 +635,8 @@ void ViewProviderMeasure::positionAnno(const Measure::MeasureBase* measureObject
Gui::View3DInventor* view = nullptr;
try {
view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
} catch (const Base::RuntimeError&) {
}
catch (const Base::RuntimeError&) {
Base::Console().Log("ViewProviderMeasure::positionAnno: Could not get active view\n");
}
@@ -636,19 +679,22 @@ void ViewProviderMeasure::redrawAnnotation()
}
Base::Vector3d ViewProviderMeasure::getBasePosition(){
Base::Vector3d ViewProviderMeasure::getBasePosition()
{
auto measureObject = getMeasureObject();
Base::Placement placement = measureObject->getPlacement();
return placement.getPosition();
}
Base::Vector3d ViewProviderMeasure::getTextPosition(){
Base::Vector3d ViewProviderMeasure::getTextPosition()
{
// Return the initial position relative to the base position
auto basePoint = getBasePosition();
Gui::View3DInventor* view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
if (!view) {
Base::Console().Log("ViewProviderMeasureBase::getTextPosition: Could not get active view\n");
Base::Console().Log(
"ViewProviderMeasureBase::getTextPosition: Could not get active view\n");
return Base::Vector3d();
}

View File

@@ -48,7 +48,8 @@ class SoTranslate2Dragger;
// NOLINTEND
namespace MeasureGui {
namespace MeasureGui
{
class MeasureGuiExport ViewProviderMeasureGroup: public Gui::ViewProviderDocumentObjectGroup
@@ -59,7 +60,8 @@ public:
ViewProviderMeasureGroup();
~ViewProviderMeasureGroup() override;
bool allowOverride(const App::DocumentObject &) const override {
bool allowOverride(const App::DocumentObject&) const override
{
return true;
}
@@ -67,7 +69,6 @@ public:
};
// NOLINTBEGIN
class MeasureGuiExport ViewProviderMeasureBase: public Gui::ViewProviderDocumentObject
{
@@ -90,13 +91,19 @@ public:
/**
* Attaches the document object to this view provider.
*/
bool isPartOfPhysicalObject() const override {return false;};
bool isPartOfPhysicalObject() const override
{
return false;
};
void attach(App::DocumentObject* pcObj) override;
void updateData(const App::Property* prop) override;
virtual void positionAnno(const Measure::MeasureBase* measureObject);
void finishRestoring() override;
bool useNewSelectionModel() const override {return true;}
bool useNewSelectionModel() const override
{
return true;
}
std::vector<std::string> getDisplayModes() const override;
void setDisplayMode(const char* ModeName) override;
/// Show the annotation in the 3d window
@@ -107,8 +114,14 @@ public:
virtual bool isSubjectVisible();
static Base::Vector3d toVector3d(SbVec3f svec) { return Base::Vector3d(svec[0], svec[1], svec[2]); }
static SbVec3f toSbVec3f(Base::Vector3d vec3) { return SbVec3f(vec3.x, vec3.y, vec3.z); }
static Base::Vector3d toVector3d(SbVec3f svec)
{
return Base::Vector3d(svec[0], svec[1], svec[2]);
}
static SbVec3f toSbVec3f(Base::Vector3d vec3)
{
return SbVec3f(vec3.x, vec3.y, vec3.z);
}
void onSubjectVisibilityChanged(const App::DocumentObject& docObj, const App::Property& prop);
void connectToSubject(App::DocumentObject* subject);
@@ -129,7 +142,8 @@ protected:
SoSeparator* getSoSeparatorText();
static constexpr double defaultTolerance = 10e-6;
virtual Base::Vector3d getTextDirection(Base::Vector3d elementDirection, double tolerance = defaultTolerance);
virtual Base::Vector3d getTextDirection(Base::Vector3d elementDirection,
double tolerance = defaultTolerance);
float getViewScale();
// TODO: getters & setters and move variables to private?
@@ -145,6 +159,7 @@ protected:
SoSeparator* pTextSeparator;
SoSeparator* pLineSeparator;
SoSeparator* pLineSeparatorSecondary;
private:
boost::signals2::connection _mVisibilityChangedConnection;
};
@@ -181,7 +196,8 @@ class ViewProviderMeasureArea : public ViewProviderMeasure
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureArea);
public:
ViewProviderMeasureArea() {
ViewProviderMeasureArea()
{
sPixmap = "Measurement-Area";
}
};
@@ -192,7 +208,8 @@ class ViewProviderMeasureLength : public ViewProviderMeasure
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureLength);
public:
ViewProviderMeasureLength() {
ViewProviderMeasureLength()
{
sPixmap = "Measurement-Distance";
}
};
@@ -203,7 +220,8 @@ class ViewProviderMeasurePosition : public ViewProviderMeasure
PROPERTY_HEADER(MeasureGui::ViewProviderMeasurePosition);
public:
ViewProviderMeasurePosition() {
ViewProviderMeasurePosition()
{
sPixmap = "Measurement-Position";
}
};
@@ -214,13 +232,13 @@ class ViewProviderMeasureRadius : public ViewProviderMeasure
PROPERTY_HEADER(MeasureGui::ViewProviderMeasureRadius);
public:
ViewProviderMeasureRadius() {
ViewProviderMeasureRadius()
{
sPixmap = "Measurement-Radius";
}
};
} // namespace Gui
} // namespace MeasureGui
#endif // GUI_VIEWPROVIDER_MEASUREMENTBASE_H

View File

@@ -231,13 +231,16 @@ void MeasureGui::DimensionLinear::setupDimension()
}
SbMatrix ViewProviderMeasureDistance::getMatrix() {
SbMatrix ViewProviderMeasureDistance::getMatrix()
{
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"));
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 {};
@@ -255,23 +258,34 @@ SbMatrix ViewProviderMeasureDistance::getMatrix() {
assert(fabs(localYAxis.Dot(localXAxis)) < tolerance);
Base::Vector3d localZAxis = localYAxis.Cross(localXAxis).Normalize();
SbMatrix matrix = SbMatrix(
localXAxis.x, localXAxis.y, localXAxis.z, 0,
localYAxis.x, localYAxis.y, localYAxis.z ,0,
localZAxis.x, localZAxis.y, localZAxis.z, 0,
SbMatrix matrix = SbMatrix(localXAxis.x,
localXAxis.y,
localXAxis.z,
0,
localYAxis.x,
localYAxis.y,
localYAxis.z,
0,
localZAxis.x,
localZAxis.y,
localZAxis.z,
0,
// 0,0,0,1
origin[0], origin[1], origin[2], 1
);
origin[0],
origin[1],
origin[2],
1);
return matrix;
}
//! calculate a good direction from the elements being measured to the annotation text based on the layout
//! of the elements and its relationship with the cardinal axes and the view direction. elementDirection
//! is expected to be a normalized vector.
//! an example of an elementDirection would be the vector from the start of a line to the end.
Base::Vector3d ViewProviderMeasureDistance::getTextDirection(Base::Vector3d elementDirection, double tolerance)
//! calculate a good direction from the elements being measured to the annotation text based on the
//! layout of the elements and its relationship with the cardinal axes and the view direction.
//! elementDirection is expected to be a normalized vector. an example of an elementDirection would
//! be the vector from the start of a line to the end.
Base::Vector3d ViewProviderMeasureDistance::getTextDirection(Base::Vector3d elementDirection,
double tolerance)
{
const Base::Vector3d stdX(1.0, 0.0, 0.0);
const Base::Vector3d stdY(0.0, 1.0, 0.0);
@@ -297,20 +311,31 @@ ViewProviderMeasureDistance::ViewProviderMeasureDistance()
{
sPixmap = "Measurement-Distance";
ADD_PROPERTY_TYPE(ShowDelta, (false), "Appearance", App::Prop_None, "Display the X, Y and Z components of the distance");
ADD_PROPERTY_TYPE(ShowDelta,
(false),
"Appearance",
App::Prop_None,
"Display the X, Y and Z components of the distance");
// vert indexes used to create the annotation lines
const size_t lineCount(3);
static const int32_t lines[lineCount] =
{
2,3,-1 // dimension line
static const int32_t lines[lineCount] = {
2,
3,
-1 // dimension line
};
const size_t lineCountSecondary(9);
static const int32_t linesSecondary[lineCountSecondary] = {
0,2,-1, // extension line 1
1,3,-1, // extension line 2
2,4,-1 // label helper line
0,
2,
-1, // extension line 1
1,
3,
-1, // extension line 2
2,
4,
-1 // label helper line
};
// Line Coordinates
@@ -354,7 +379,8 @@ ViewProviderMeasureDistance::ViewProviderMeasureDistance()
pLineSeparatorSecondary->addChild(lineSetSecondary);
auto points = new SoMarkerSet();
points->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex("CROSS",
points->markerIndex =
Gui::Inventor::MarkerBitmaps::getMarkerIndex("CROSS",
ViewParams::instance()->getMarkerSize());
points->numPoints = 2;
pLineSeparator->addChild(points);
@@ -432,8 +458,10 @@ void ViewProviderMeasureDistance::redrawAnnotation()
return;
}
auto prop1 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position1"));
auto prop2 = Base::freecad_dynamic_cast<App::PropertyVector>(pcObject->getPropertyByName("Position2"));
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;
@@ -448,19 +476,23 @@ void ViewProviderMeasureDistance::redrawAnnotation()
// Set the distance
fieldDistance = (vec2 - vec1).Length();
auto propDistance = dynamic_cast<App::PropertyDistance*>(pcObject->getPropertyByName("Distance"));
auto propDistance =
dynamic_cast<App::PropertyDistance*>(pcObject->getPropertyByName("Distance"));
setLabelValue(propDistance->getQuantityValue().getUserString());
// Set delta distance
auto propDistanceX = static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceX"));
auto propDistanceX =
static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceX"));
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(0))
->text.setValue("Δx: " + propDistanceX->getQuantityValue().getUserString().toUtf8());
auto propDistanceY = static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceY"));
auto propDistanceY =
static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceY"));
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(1))
->text.setValue("Δy: " + propDistanceY->getQuantityValue().getUserString().toUtf8());
auto propDistanceZ = static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceZ"));
auto propDistanceZ =
static_cast<App::PropertyDistance*>(getMeasureObject()->getPropertyByName("DistanceZ"));
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(2))
->text.setValue("Δz: " + propDistanceZ->getQuantityValue().getUserString().toUtf8());
@@ -472,19 +504,29 @@ void ViewProviderMeasureDistance::redrawAnnotation()
updateView();
}
void ViewProviderMeasureDistance::onChanged(const App::Property* prop) {
void ViewProviderMeasureDistance::onChanged(const App::Property* prop)
{
if (prop == &ShowDelta) {
pDeltaDimensionSwitch->whichChild.setValue(ShowDelta.getValue() ? SO_SWITCH_ALL : SO_SWITCH_NONE);
} else if (prop == &FontSize) {
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(0))->fontSize.setValue(FontSize.getValue());
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(1))->fontSize.setValue(FontSize.getValue());
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(2))->fontSize.setValue(FontSize.getValue());
} else if (prop == &TextBackgroundColor) {
pDeltaDimensionSwitch->whichChild.setValue(ShowDelta.getValue() ? SO_SWITCH_ALL
: SO_SWITCH_NONE);
}
else if (prop == &FontSize) {
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(0))
->fontSize.setValue(FontSize.getValue());
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(1))
->fontSize.setValue(FontSize.getValue());
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(2))
->fontSize.setValue(FontSize.getValue());
}
else if (prop == &TextBackgroundColor) {
auto bColor = TextBackgroundColor.getValue();
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(0))->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(1))->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(2))->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(0))
->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(1))
->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
static_cast<DimensionLinear*>(pDeltaDimensionSwitch->getChild(2))
->backgroundColor.setValue(bColor.r, bColor.g, bColor.g);
}
@@ -492,7 +534,8 @@ void ViewProviderMeasureDistance::onChanged(const App::Property* prop) {
}
void ViewProviderMeasureDistance::positionAnno(const Measure::MeasureBase* measureObject) {
void ViewProviderMeasureDistance::positionAnno(const Measure::MeasureBase* measureObject)
{
(void)measureObject;
setLabelTranslation(SbVec3f(0, 0.1 * getViewScale(), 0));
}

View File

@@ -82,7 +82,6 @@ private:
};
class MeasureGuiExport ViewProviderMeasureDistance: public MeasureGui::ViewProviderMeasureBase
{
PROPERTY_HEADER_WITH_OVERRIDE(MeasureGui::ViewProviderMeasureDistance);
@@ -98,7 +97,8 @@ public:
void positionAnno(const Measure::MeasureBase* measureObject) override;
protected:
Base::Vector3d getTextDirection(Base::Vector3d elementDirection, double tolerance = defaultTolerance) override;
Base::Vector3d getTextDirection(Base::Vector3d elementDirection,
double tolerance = defaultTolerance) override;
void onChanged(const App::Property* prop) override;
private:

View File

@@ -38,7 +38,8 @@ void WorkbenchManipulator::modifyMenuBar([[maybe_unused]] Gui::MenuItem* menuBar
menuTools->appendItem(itemMeasure);
}
void WorkbenchManipulator::modifyToolBars(Gui::ToolBarItem* toolBar) {
void WorkbenchManipulator::modifyToolBars(Gui::ToolBarItem* toolBar)
{
auto tbView = toolBar->findItem("View");
if (!tbView) {
return;

View File

@@ -25,7 +25,8 @@
#include <Gui/WorkbenchManipulator.h>
namespace MeasureGui {
namespace MeasureGui
{
class WorkbenchManipulator: public Gui::WorkbenchManipulator
{

View File

@@ -36,6 +36,7 @@ Measure.makeMeasureCOM = makeMeasureCOM
# Register python measure types
import FreeCAD
FreeCAD.MeasureManager.addMeasureType(
"CENTEROFMASS",
"Center of Mass",

View File

@@ -25,13 +25,11 @@ from UtilsMeasure import MeasureBasePython
from PySide.QtCore import QT_TRANSLATE_NOOP
__title__ = "Measure Center of Mass Object"
__author__ = "David Friedli"
__url__ = "http://www.freecad.org"
"""
The Measure cpp object defines a result and a placement property. The Python measure type
adds it's own specific properties. Once the object is recomputed the parent properties are updated
@@ -42,9 +40,8 @@ __url__ = "http://www.freecad.org"
"""
def makeMeasureCOM(name="CenterOfMass"):
'''makeMeasureCOM(name): make a CenterofMass measurement'''
"""makeMeasureCOM(name): make a CenterofMass measurement"""
obj = FreeCAD.ActiveDocument.addObject("Measure::MeasurePython", name)
MeasureCOM(obj)
return obj
@@ -56,8 +53,18 @@ class MeasureCOM(MeasureBasePython):
def __init__(self, obj):
obj.Proxy = self
obj.addProperty("App::PropertyLinkSubGlobal", "Element", "", QT_TRANSLATE_NOOP("App::Property", "Element to measure"))
obj.addProperty("App::PropertyPosition", "Result", "", QT_TRANSLATE_NOOP("App::PropertyVector", "The result location"))
obj.addProperty(
"App::PropertyLinkSubGlobal",
"Element",
"",
QT_TRANSLATE_NOOP("App::Property", "Element to measure"),
)
obj.addProperty(
"App::PropertyPosition",
"Result",
"",
QT_TRANSLATE_NOOP("App::PropertyVector", "The result location"),
)
@classmethod
def isValidSelection(cls, selection):
@@ -101,13 +108,11 @@ class MeasureCOM(MeasureBasePython):
return ()
return (ob,)
def parseSelection(self, obj, selection):
item = selection[0]
o = item["object"]
obj.Element = (o, item["subName"])
def getResultString(self, obj):
values = [Units.Quantity(v, Units.Length).getUserPreferred()[0] for v in obj.Result]
return "COM\nX: {}\nY: {}\nZ: {}".format(*values)
@@ -144,9 +149,8 @@ class MeasureCOM(MeasureBasePython):
placement.Base = com
obj.Placement = placement
def onChanged(self, obj, prop):
'''Do something when a property has changed'''
"""Do something when a property has changed"""
if prop == "Element":
self.execute(obj)

View File

@@ -22,6 +22,7 @@
from abc import ABC, abstractmethod, abstractclassmethod
from typing import List, Tuple
class MeasureBasePython(ABC):
@abstractclassmethod
@@ -48,5 +49,3 @@ class MeasureBasePython(ABC):
def parseSelection(self, obj, selection):
"""Sets the measurements properties from the given selection"""
pass