[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
@@ -43,7 +43,8 @@
|
||||
#include "MeasureArea.h"
|
||||
#include "MeasureRadius.h"
|
||||
|
||||
namespace Measure {
|
||||
namespace Measure
|
||||
{
|
||||
|
||||
// explicit template instantiations
|
||||
template class MeasureExport MeasureBaseExtendable<Part::MeasureAngleInfo>;
|
||||
@@ -54,12 +55,13 @@ template class MeasureExport MeasureBaseExtendable<Part::MeasurePositionInfo>;
|
||||
template class MeasureExport MeasureBaseExtendable<Part::MeasureRadiusInfo>;
|
||||
|
||||
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
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
|
||||
initialize("This module is the Measure module."); // register with Python
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -70,7 +72,7 @@ PyObject* initModule()
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
} // namespace Measure
|
||||
} // namespace Measure
|
||||
|
||||
using namespace Measure;
|
||||
|
||||
@@ -81,7 +83,7 @@ PyMOD_INIT_FUNC(Measure)
|
||||
try {
|
||||
Base::Interpreter().runString("import Part");
|
||||
}
|
||||
catch(const Base::Exception& e) {
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ImportError, e.what());
|
||||
PyMOD_Return(nullptr);
|
||||
}
|
||||
@@ -90,100 +92,94 @@ PyMOD_INIT_FUNC(Measure)
|
||||
Base::Interpreter().addType(&Measure::MeasurementPy::Type, mod, "Measurement");
|
||||
Base::Interpreter().addType(&Measure::MeasureBasePy::Type, mod, "MeasureBase");
|
||||
|
||||
Measure::Measurement ::init();
|
||||
Measure::Measurement ::init();
|
||||
|
||||
// umf classes
|
||||
Measure::MeasureDistanceType ::init();
|
||||
Measure::MeasureBase ::init();
|
||||
Measure::MeasurePython ::init();
|
||||
Measure::MeasureAngle ::init();
|
||||
Measure::MeasureDistance ::init();
|
||||
Measure::MeasureDistanceType ::init();
|
||||
Measure::MeasureBase ::init();
|
||||
Measure::MeasurePython ::init();
|
||||
Measure::MeasureAngle ::init();
|
||||
Measure::MeasureDistance ::init();
|
||||
Measure::MeasureDistanceDetached::init();
|
||||
Measure::MeasurePosition ::init();
|
||||
Measure::MeasureLength ::init();
|
||||
Measure::MeasureArea ::init();
|
||||
Measure::MeasureRadius ::init();
|
||||
Measure::MeasurePosition ::init();
|
||||
Measure::MeasureLength ::init();
|
||||
Measure::MeasureArea ::init();
|
||||
Measure::MeasureRadius ::init();
|
||||
|
||||
// Add fundamental umf Measure Types
|
||||
|
||||
App::MeasureManager::addMeasureType("DISTANCE",
|
||||
"Distance",
|
||||
"Measure::MeasureDistance",
|
||||
MeasureDistance::isValidSelection,
|
||||
MeasureDistance::isPrioritizedSelection
|
||||
);
|
||||
"Distance",
|
||||
"Measure::MeasureDistance",
|
||||
MeasureDistance::isValidSelection,
|
||||
MeasureDistance::isPrioritizedSelection);
|
||||
|
||||
App::MeasureManager::addMeasureType("DISTANCEFREE",
|
||||
"Distance Free",
|
||||
"Measure::MeasureDistanceDetached",
|
||||
MeasureDistanceDetached::isValidSelection,
|
||||
nullptr
|
||||
);
|
||||
"Distance Free",
|
||||
"Measure::MeasureDistanceDetached",
|
||||
MeasureDistanceDetached::isValidSelection,
|
||||
nullptr);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"ANGLE",
|
||||
"Angle",
|
||||
"Measure::MeasureAngle",
|
||||
MeasureAngle::isValidSelection,
|
||||
MeasureAngle::isPrioritizedSelection
|
||||
);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"LENGTH",
|
||||
"Length",
|
||||
"Measure::MeasureLength",
|
||||
MeasureLength::isValidSelection,
|
||||
nullptr
|
||||
);
|
||||
App::MeasureManager::addMeasureType("ANGLE",
|
||||
"Angle",
|
||||
"Measure::MeasureAngle",
|
||||
MeasureAngle::isValidSelection,
|
||||
MeasureAngle::isPrioritizedSelection);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"POSITION",
|
||||
"Position",
|
||||
"Measure::MeasurePosition",
|
||||
MeasurePosition::isValidSelection,
|
||||
nullptr
|
||||
);
|
||||
App::MeasureManager::addMeasureType("LENGTH",
|
||||
"Length",
|
||||
"Measure::MeasureLength",
|
||||
MeasureLength::isValidSelection,
|
||||
nullptr);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"AREA",
|
||||
"Area",
|
||||
"Measure::MeasureArea",
|
||||
MeasureArea::isValidSelection,
|
||||
nullptr
|
||||
);
|
||||
|
||||
App::MeasureManager::addMeasureType(
|
||||
"RADIUS",
|
||||
"Radius",
|
||||
"Measure::MeasureRadius",
|
||||
MeasureRadius::isValidSelection,
|
||||
MeasureRadius::isPrioritizedSelection
|
||||
);
|
||||
App::MeasureManager::addMeasureType("POSITION",
|
||||
"Position",
|
||||
"Measure::MeasurePosition",
|
||||
MeasurePosition::isValidSelection,
|
||||
nullptr);
|
||||
|
||||
App::MeasureManager::addMeasureType("AREA",
|
||||
"Area",
|
||||
"Measure::MeasureArea",
|
||||
MeasureArea::isValidSelection,
|
||||
nullptr);
|
||||
|
||||
App::MeasureManager::addMeasureType("RADIUS",
|
||||
"Radius",
|
||||
"Measure::MeasureRadius",
|
||||
MeasureRadius::isValidSelection,
|
||||
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();
|
||||
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);
|
||||
for (auto& entry : radiusList) {
|
||||
MeasureBaseExtendable<Part::MeasureRadiusInfo>::addGeometryHandler(entry.m_module,
|
||||
entry.m_callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +187,7 @@ PyMOD_INIT_FUNC(Measure)
|
||||
PyMOD_Return(mod);
|
||||
}
|
||||
|
||||
// debug print for sketchsolv
|
||||
// debug print for sketchsolv
|
||||
void debugprint(const std::string& text)
|
||||
{
|
||||
Base::Console().Log("%s", text.c_str());
|
||||
|
||||
@@ -38,16 +38,27 @@ 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),
|
||||
"Angle between the two elements");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +91,7 @@ bool MeasureAngle::isPrioritizedSelection(const App::MeasureSelection& selection
|
||||
if (selection.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Check if the two elements are parallel
|
||||
auto element1 = selection.at(0);
|
||||
auto objT1 = element1.object;
|
||||
@@ -97,13 +107,14 @@ bool MeasureAngle::isPrioritizedSelection(const App::MeasureSelection& selection
|
||||
Base::Vector3d vec2;
|
||||
getVec(*ob2, sub2, vec2);
|
||||
|
||||
|
||||
|
||||
double angle = std::fmod(vec1.GetAngle(vec2), D_PI);
|
||||
return angle > Base::Precision::Angular();
|
||||
}
|
||||
|
||||
|
||||
void MeasureAngle::parseSelection(const App::MeasureSelection& selection) {
|
||||
void MeasureAngle::parseSelection(const App::MeasureSelection& selection)
|
||||
{
|
||||
|
||||
assert(selection.size() >= 2);
|
||||
|
||||
@@ -121,8 +132,9 @@ void MeasureAngle::parseSelection(const App::MeasureSelection& selection) {
|
||||
}
|
||||
|
||||
|
||||
bool MeasureAngle::getVec(App::DocumentObject& ob, std::string& subName, Base::Vector3d& vecOut) {
|
||||
App::SubObjectT subject{&ob, subName.c_str()};
|
||||
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) {
|
||||
return false;
|
||||
@@ -135,22 +147,23 @@ bool MeasureAngle::getVec(App::DocumentObject& ob, std::string& subName, Base::V
|
||||
|
||||
Base::Vector3d MeasureAngle::getLoc(App::DocumentObject& ob, std::string& subName)
|
||||
{
|
||||
App::SubObjectT subject{&ob, subName.c_str()};
|
||||
App::SubObjectT subject {&ob, subName.c_str()};
|
||||
auto info = getMeasureInfo(subject);
|
||||
if (!info || !info->valid) {
|
||||
return Base::Vector3d();
|
||||
}
|
||||
|
||||
if (!info || !info->valid) {
|
||||
return Base::Vector3d();
|
||||
}
|
||||
|
||||
auto angleInfo = std::dynamic_pointer_cast<Part::MeasureAngleInfo>(info);
|
||||
return angleInfo->position;
|
||||
}
|
||||
|
||||
gp_Vec MeasureAngle::vector1() {
|
||||
gp_Vec MeasureAngle::vector1()
|
||||
{
|
||||
|
||||
App::DocumentObject* ob = Element1.getValue();
|
||||
std::vector<std::string> subs = Element1.getSubValues();
|
||||
|
||||
if (!ob || !ob->isValid() || subs.empty() ) {
|
||||
if (!ob || !ob->isValid() || subs.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -159,11 +172,12 @@ 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();
|
||||
|
||||
if (!ob || !ob->isValid() || subs.empty() ) {
|
||||
if (!ob || !ob->isValid() || subs.empty()) {
|
||||
return gp_Vec();
|
||||
}
|
||||
|
||||
@@ -172,22 +186,24 @@ 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();
|
||||
|
||||
if (!ob || !ob->isValid() || subs.empty() ) {
|
||||
if (!ob || !ob->isValid() || subs.empty()) {
|
||||
return {};
|
||||
}
|
||||
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();
|
||||
|
||||
if (!ob || !ob->isValid() || subs.empty() ) {
|
||||
if (!ob || !ob->isValid() || subs.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -195,7 +211,7 @@ gp_Vec MeasureAngle::location2() {
|
||||
return {temp.x, temp.y, temp.z};
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureAngle::execute()
|
||||
App::DocumentObjectExecReturn* MeasureAngle::execute()
|
||||
{
|
||||
App::DocumentObject* ob1 = Element1.getValue();
|
||||
std::vector<std::string> subs1 = Element1.getSubValues();
|
||||
@@ -227,7 +243,7 @@ void MeasureAngle::onChanged(const App::Property* prop)
|
||||
|
||||
if (prop == &Element1 || prop == &Element2) {
|
||||
if (!isRestoring()) {
|
||||
App::DocumentObjectExecReturn *ret = recompute();
|
||||
App::DocumentObjectExecReturn* ret = recompute();
|
||||
delete ret;
|
||||
}
|
||||
}
|
||||
@@ -240,4 +256,3 @@ std::vector<App::DocumentObject*> MeasureAngle::getSubject() const
|
||||
{
|
||||
return {Element1.getValue()};
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Measure
|
||||
{
|
||||
|
||||
|
||||
class MeasureExport MeasureAngle : public Measure::MeasureBaseExtendable<Part::MeasureAngleInfo>
|
||||
class MeasureExport MeasureAngle: public Measure::MeasureBaseExtendable<Part::MeasureAngleInfo>
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureAngle);
|
||||
|
||||
@@ -54,9 +54,10 @@ public:
|
||||
App::PropertyLinkSub Element2;
|
||||
App::PropertyAngle Angle;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
App::DocumentObjectExecReturn* execute() override;
|
||||
|
||||
const char* getViewProviderName() const override {
|
||||
const char* getViewProviderName() const override
|
||||
{
|
||||
return "MeasureGui::ViewProviderMeasureAngle";
|
||||
}
|
||||
|
||||
@@ -64,10 +65,16 @@ 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
|
||||
// Return the object we are measuring
|
||||
std::vector<App::DocumentObject*> getSubject() const override;
|
||||
|
||||
|
||||
@@ -81,13 +88,12 @@ public:
|
||||
// Location Vectors
|
||||
gp_Vec location1();
|
||||
gp_Vec location2();
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
void onChanged(const App::Property* prop) override;
|
||||
};
|
||||
|
||||
} //namespace Measure
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // APP_MEASUREANGLE_H
|
||||
#endif // APP_MEASUREANGLE_H
|
||||
|
||||
@@ -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),
|
||||
"Area of element");
|
||||
|
||||
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;
|
||||
@@ -87,7 +94,7 @@ void MeasureArea::parseSelection(const App::MeasureSelection& selection) {
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureArea::execute()
|
||||
App::DocumentObjectExecReturn* MeasureArea::execute()
|
||||
{
|
||||
recalculateArea();
|
||||
return DocumentObject::StdReturn;
|
||||
@@ -101,8 +108,8 @@ void MeasureArea::recalculateArea()
|
||||
double result(0.0);
|
||||
|
||||
// Loop through Elements and call the valid geometry handler
|
||||
for (std::vector<App::DocumentObject*>::size_type i=0; i<objects.size(); i++) {
|
||||
App::SubObjectT subject{objects.at(i), subElements.at(i).c_str()};
|
||||
for (std::vector<App::DocumentObject*>::size_type i = 0; i < objects.size(); i++) {
|
||||
App::SubObjectT subject {objects.at(i), subElements.at(i).c_str()};
|
||||
|
||||
auto info = getMeasureInfo(subject);
|
||||
if (!info || !info->valid) {
|
||||
@@ -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();
|
||||
|
||||
@@ -137,7 +145,7 @@ Base::Placement MeasureArea::getPlacement() {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
App::SubObjectT subject{objects.front(), subElements.front().c_str()};
|
||||
App::SubObjectT subject {objects.front(), subElements.front().c_str()};
|
||||
|
||||
auto info = getMeasureInfo(subject);
|
||||
if (!info) {
|
||||
|
||||
@@ -40,9 +40,7 @@ namespace Measure
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
class MeasureExport MeasureArea : public Measure::MeasureBaseExtendable<Part::MeasureAreaInfo>
|
||||
class MeasureExport MeasureArea: public Measure::MeasureBaseExtendable<Part::MeasureAreaInfo>
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureArea);
|
||||
|
||||
@@ -54,18 +52,25 @@ public:
|
||||
App::PropertyLinkSubList Elements;
|
||||
App::PropertyArea Area;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
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
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASURE_MEASUREAREA_H
|
||||
|
||||
#endif // MEASURE_MEASUREAREA_H
|
||||
|
||||
@@ -35,13 +35,18 @@ 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");
|
||||
}
|
||||
|
||||
|
||||
PyObject *MeasureBase::getPyObject(void)
|
||||
PyObject* MeasureBase::getPyObject(void)
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
@@ -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();
|
||||
@@ -67,11 +74,12 @@ std::vector<App::DocumentObject*> MeasureBase::getSubject() const {
|
||||
// Pass the feature object to the proxy
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(const_cast<MeasureBase*>(this)->getPyObject()));
|
||||
|
||||
|
||||
Py::Object ret;
|
||||
try {
|
||||
ret = proxy.callMemberFunction("getSubject", args);
|
||||
} catch (Py::Exception&) {
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e;
|
||||
e.ReportException();
|
||||
return {};
|
||||
@@ -84,14 +92,13 @@ std::vector<App::DocumentObject*> MeasureBase::getSubject() const {
|
||||
}
|
||||
|
||||
return retVec;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
void MeasureBase::parseSelection(const App::MeasureSelection& selection) {
|
||||
void MeasureBase::parseSelection(const App::MeasureSelection& selection)
|
||||
{
|
||||
Base::PyGILStateLocker lock;
|
||||
|
||||
|
||||
Py::Object proxy = getProxyObject();
|
||||
|
||||
// Convert selection to python list
|
||||
@@ -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,11 +151,11 @@ std::vector<std::string> MeasureBase::getInputProps() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString MeasureBase::getResultString() {
|
||||
QString MeasureBase::getResultString()
|
||||
{
|
||||
Py::Object proxy = getProxyObject();
|
||||
Base::PyGILStateLocker lock;
|
||||
|
||||
|
||||
if (!proxy.isNone()) {
|
||||
|
||||
// Pass the feature object to the proxy
|
||||
@@ -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();
|
||||
@@ -165,9 +175,9 @@ QString MeasureBase::getResultString() {
|
||||
}
|
||||
|
||||
App::Property* prop = getResultProp();
|
||||
if (prop == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
if (prop == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
if (prop->isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
|
||||
return static_cast<App::PropertyQuantity*>(prop)->getQuantityValue().getUserString();
|
||||
@@ -177,28 +187,35 @@ 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);
|
||||
PythonObject = Py::Object(new FeaturePythonPyT<Measure::MeasureBasePy>(this), true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
@@ -206,6 +223,4 @@ template<> PyObject* Measure::MeasurePython::getPyObject() {
|
||||
|
||||
// explicit template instantiation
|
||||
template class MeasureExport FeaturePythonT<Measure::MeasureBase>;
|
||||
}
|
||||
|
||||
|
||||
} // namespace App
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
namespace Measure
|
||||
{
|
||||
|
||||
class MeasureExport MeasureBase : public App::DocumentObject
|
||||
class MeasureExport MeasureBase: public App::DocumentObject
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureBase);
|
||||
|
||||
@@ -58,8 +58,8 @@ public:
|
||||
|
||||
// boost::signals2::signal<void (const MeasureBase*)> signalGuiInit;
|
||||
|
||||
//return PyObject as MeasureBasePy
|
||||
PyObject *getPyObject() override;
|
||||
// return PyObject as MeasureBasePy
|
||||
PyObject* getPyObject() override;
|
||||
|
||||
// Initialize measurement properties from selection
|
||||
virtual void parseSelection(const App::MeasureSelection& selection);
|
||||
@@ -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
|
||||
@@ -84,21 +87,22 @@ protected:
|
||||
// Create a scriptable object based on MeasureBase
|
||||
using MeasurePython = App::FeaturePythonT<MeasureBase>;
|
||||
|
||||
template <typename T>
|
||||
class MeasureExport MeasureBaseExtendable : public MeasureBase
|
||||
template<typename T>
|
||||
class MeasureExport MeasureBaseExtendable: public MeasureBase
|
||||
{
|
||||
|
||||
using GeometryHandler = std::function<Part::MeasureInfoPtr (const App::SubObjectT&)>;
|
||||
using GeometryHandler = std::function<Part::MeasureInfoPtr(const App::SubObjectT&)>;
|
||||
using HandlerMap = std::map<std::string, GeometryHandler>;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static void addGeometryHandler(const std::string& module, GeometryHandler callback) {
|
||||
public:
|
||||
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();
|
||||
@@ -119,26 +124,30 @@ public:
|
||||
// Get the Geometry handler based on the module
|
||||
const char* className = sub->getTypeId().getName();
|
||||
std::string mod = Base::Type::getModuleName(className);
|
||||
|
||||
|
||||
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,8 +156,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace Measure
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASURE_MEASUREBASE_H
|
||||
#endif // MEASURE_MEASUREBASE_H
|
||||
|
||||
@@ -16,7 +16,7 @@ std::string MeasureBasePy::representation() const
|
||||
return "<Measure::MeasureBase>";
|
||||
}
|
||||
|
||||
PyObject *MeasureBasePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
PyObject* MeasureBasePy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of MeasureBasePy and the Twin object
|
||||
return new MeasureBasePy(new MeasureBase);
|
||||
@@ -26,10 +26,10 @@ PyObject *MeasureBasePy::PyMake(struct _typeobject *, PyObject *, PyObject *) /
|
||||
// constructor method
|
||||
int MeasureBasePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *MeasureBasePy::getCustomAttributes(const char* /*attr*/) const
|
||||
PyObject* MeasureBasePy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
"Distance between the two elements");
|
||||
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),
|
||||
"Distance in X direction");
|
||||
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),
|
||||
"Distance in Y direction");
|
||||
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),
|
||||
"Distance in Z direction");
|
||||
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,17 +154,18 @@ 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();
|
||||
|
||||
if (!ob || !ob->isValid() || subs.empty() ) {
|
||||
if (!ob || !ob->isValid() || subs.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string subName = subs.at(0);
|
||||
App::SubObjectT subject{ob, subName.c_str()};
|
||||
App::SubObjectT subject {ob, subName.c_str()};
|
||||
|
||||
auto info = getMeasureInfo(subject);
|
||||
|
||||
@@ -153,7 +179,7 @@ bool MeasureDistance::getShape(App::PropertyLinkSub* prop, TopoDS_Shape& rShape)
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureDistance::execute()
|
||||
App::DocumentObjectExecReturn* MeasureDistance::execute()
|
||||
{
|
||||
|
||||
App::DocumentObject* ob1 = Element1.getValue();
|
||||
@@ -207,7 +233,7 @@ void MeasureDistance::onChanged(const App::Property* prop)
|
||||
|
||||
if (prop == &Element1 || prop == &Element2) {
|
||||
if (!isRestoring()) {
|
||||
App::DocumentObjectExecReturn *ret = recompute();
|
||||
App::DocumentObjectExecReturn* ret = recompute();
|
||||
delete ret;
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
"Distance between the two elements");
|
||||
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),
|
||||
"Distance in X direction");
|
||||
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),
|
||||
"Distance in Y direction");
|
||||
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),
|
||||
"Distance in Z direction");
|
||||
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);
|
||||
|
||||
@@ -262,7 +309,7 @@ void MeasureDistanceDetached::parseSelection(const App::MeasureSelection& select
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureDistanceDetached::execute()
|
||||
App::DocumentObjectExecReturn* MeasureDistanceDetached::execute()
|
||||
{
|
||||
recalculateDistance();
|
||||
return DocumentObject::StdReturn;
|
||||
@@ -297,7 +344,6 @@ std::vector<App::DocumentObject*> MeasureDistanceDetached::getSubject() const
|
||||
}
|
||||
|
||||
|
||||
|
||||
Base::Type MeasureDistanceType::getClassTypeId()
|
||||
{
|
||||
return Base::Type::badType();
|
||||
@@ -324,11 +370,10 @@ void* MeasureDistanceType::create()
|
||||
Base::Type MeasureDistanceType::classTypeId = Base::Type::badType();
|
||||
|
||||
|
||||
|
||||
// Migrate old MeasureDistance Type
|
||||
void MeasureDistanceDetached::handleChangedPropertyName(Base::XMLReader &reader,
|
||||
const char * TypeName,
|
||||
const char *PropName)
|
||||
void MeasureDistanceDetached::handleChangedPropertyName(Base::XMLReader& reader,
|
||||
const char* TypeName,
|
||||
const char* PropName)
|
||||
{
|
||||
if (strcmp(PropName, "P1") == 0 && strcmp(TypeName, "App::PropertyVector") == 0) {
|
||||
Position1.Restore(reader);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -71,9 +72,10 @@ public:
|
||||
App::PropertyVector Position1;
|
||||
App::PropertyVector Position2;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
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,15 +99,11 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void onChanged(const App::Property* prop) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MeasureExport MeasureDistanceDetached : public Measure::MeasureBase
|
||||
class MeasureExport MeasureDistanceDetached: public Measure::MeasureBase
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureDistanceDetached);
|
||||
|
||||
@@ -116,33 +120,39 @@ public:
|
||||
App::PropertyVector Position1;
|
||||
App::PropertyVector Position2;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
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;
|
||||
|
||||
void handleChangedPropertyName(Base::XMLReader &reader,
|
||||
const char * TypeName,
|
||||
const char *PropName) override;
|
||||
void handleChangedPropertyName(Base::XMLReader& reader,
|
||||
const char* TypeName,
|
||||
const char* PropName) override;
|
||||
|
||||
private:
|
||||
void onChanged(const App::Property* prop) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace Measure
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASUREAPP_MEASUREDISTANCE_H
|
||||
#endif // MEASUREAPP_MEASUREDISTANCE_H
|
||||
|
||||
@@ -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),
|
||||
"Length of selection");
|
||||
|
||||
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;
|
||||
@@ -65,14 +71,15 @@ bool MeasureLength::isValidSelection(const App::MeasureSelection& selection){
|
||||
}
|
||||
|
||||
if ((type != App::MeasureElementType::LINESEGMENT && type != App::MeasureElementType::CIRCLE
|
||||
&& type != App::MeasureElementType::ARC && type != App::MeasureElementType::CURVE)) {
|
||||
&& type != App::MeasureElementType::ARC && type != App::MeasureElementType::CURVE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -89,7 +96,7 @@ void MeasureLength::parseSelection(const App::MeasureSelection& selection) {
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureLength::execute()
|
||||
App::DocumentObjectExecReturn* MeasureLength::execute()
|
||||
{
|
||||
recalculateLength();
|
||||
return DocumentObject::StdReturn;
|
||||
@@ -103,9 +110,9 @@ void MeasureLength::recalculateLength()
|
||||
double result(0.0);
|
||||
|
||||
// Loop through Elements and call the valid geometry handler
|
||||
for (std::vector<App::DocumentObject*>::size_type i=0; i<objects.size(); i++) {
|
||||
for (std::vector<App::DocumentObject*>::size_type i = 0; i < objects.size(); i++) {
|
||||
|
||||
App::SubObjectT subject{objects.at(i), subElements.at(i).c_str()};
|
||||
App::SubObjectT subject {objects.at(i), subElements.at(i).c_str()};
|
||||
auto info = getMeasureInfo(subject);
|
||||
if (!info || !info->valid) {
|
||||
continue;
|
||||
@@ -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();
|
||||
|
||||
@@ -140,7 +148,7 @@ Base::Placement MeasureLength::getPlacement() {
|
||||
return Base::Placement();
|
||||
}
|
||||
|
||||
App::SubObjectT subject{objects.front(), subElements.front().c_str()};
|
||||
App::SubObjectT subject {objects.front(), subElements.front().c_str()};
|
||||
auto info = getMeasureInfo(subject);
|
||||
|
||||
if (!info || !info->valid) {
|
||||
@@ -157,4 +165,3 @@ std::vector<App::DocumentObject*> MeasureLength::getSubject() const
|
||||
{
|
||||
return Elements.getValues();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
namespace Measure
|
||||
{
|
||||
|
||||
class MeasureExport MeasureLength : public Measure::MeasureBaseExtendable<Part::MeasureLengthInfo>
|
||||
class MeasureExport MeasureLength: public Measure::MeasureBaseExtendable<Part::MeasureLengthInfo>
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureLength);
|
||||
|
||||
@@ -49,18 +49,25 @@ public:
|
||||
App::PropertyLinkSubList Elements;
|
||||
App::PropertyDistance Length;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
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
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASURE_MEASURELENGTH_H
|
||||
|
||||
#endif // MEASURE_MEASURELENGTH_H
|
||||
|
||||
@@ -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),
|
||||
"The absolute position");
|
||||
|
||||
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) {
|
||||
@@ -84,7 +91,7 @@ void MeasurePosition::parseSelection(const App::MeasureSelection& selection) {
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasurePosition::execute()
|
||||
App::DocumentObjectExecReturn* MeasurePosition::execute()
|
||||
{
|
||||
recalculatePosition();
|
||||
return DocumentObject::StdReturn;
|
||||
@@ -95,9 +102,9 @@ void MeasurePosition::recalculatePosition()
|
||||
const App::DocumentObject* object = Element.getValue();
|
||||
const std::vector<std::string>& subElements = Element.getSubValues();
|
||||
|
||||
App::SubObjectT subject{object, subElements.front().c_str()};
|
||||
App::SubObjectT subject {object, subElements.front().c_str()};
|
||||
auto info = getMeasureInfo(subject);
|
||||
|
||||
|
||||
if (!info || !info->valid) {
|
||||
return;
|
||||
}
|
||||
@@ -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 {};
|
||||
@@ -129,22 +137,23 @@ QString MeasurePosition::getResultString() {
|
||||
QString unit = Position.getUnit().getString();
|
||||
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
|
||||
<< "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
|
||||
<< "Z: " << QString::number(value.z, 'f', precision) << " " << unit;
|
||||
#endif
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
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
|
||||
<< "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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -52,18 +53,25 @@ public:
|
||||
App::PropertyLinkSub Element;
|
||||
App::PropertyPosition Position;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
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,11 +80,10 @@ public:
|
||||
std::vector<App::DocumentObject*> getSubject() const override;
|
||||
|
||||
private:
|
||||
|
||||
void onChanged(const App::Property* prop) override;
|
||||
};
|
||||
|
||||
} //namespace Measure
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // APP_MEASUREPOSITION_H
|
||||
#endif // APP_MEASUREPOSITION_H
|
||||
|
||||
@@ -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),
|
||||
"Radius of selection");
|
||||
|
||||
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,16 +107,17 @@ 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;
|
||||
|
||||
std::vector<std::string> subElementList { objT.getSubName() };
|
||||
std::vector<std::string> subElementList {objT.getSubName()};
|
||||
Element.setValue(objT.getObject(), subElementList);
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *MeasureRadius::execute()
|
||||
App::DocumentObjectExecReturn* MeasureRadius::execute()
|
||||
{
|
||||
recalculateRadius();
|
||||
return DocumentObject::StdReturn;
|
||||
@@ -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);
|
||||
@@ -159,14 +166,14 @@ Part::MeasureRadiusInfoPtr MeasureRadius::getMeasureInfoFirst() const
|
||||
const std::vector<std::string>& subElements = Element.getSubValues();
|
||||
|
||||
if (!object || subElements.empty()) {
|
||||
// NOLINTNEXTLINE(modernize-return-braced-init-list)
|
||||
// NOLINTNEXTLINE(modernize-return-braced-init-list)
|
||||
return std::make_shared<Part::MeasureRadiusInfo>();
|
||||
}
|
||||
|
||||
App::SubObjectT subject{object, subElements.front().c_str()};
|
||||
App::SubObjectT subject {object, subElements.front().c_str()};
|
||||
auto info = getMeasureInfo(subject);
|
||||
if (!info || !info->valid) {
|
||||
// NOLINTNEXTLINE(modernize-return-braced-init-list)
|
||||
// NOLINTNEXTLINE(modernize-return-braced-init-list)
|
||||
return std::make_shared<Part::MeasureRadiusInfo>();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Measure
|
||||
{
|
||||
|
||||
|
||||
class MeasureExport MeasureRadius : public Measure::MeasureBaseExtendable<Part::MeasureRadiusInfo>
|
||||
class MeasureExport MeasureRadius: public Measure::MeasureBaseExtendable<Part::MeasureRadiusInfo>
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureRadius);
|
||||
|
||||
@@ -52,8 +52,9 @@ public:
|
||||
App::PropertyLinkSub Element;
|
||||
App::PropertyDistance Radius;
|
||||
|
||||
App::DocumentObjectExecReturn *execute() override;
|
||||
const char* getViewProviderName() const override {
|
||||
App::DocumentObjectExecReturn* execute() 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
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASURE_MEASURERADIUS_H
|
||||
|
||||
@@ -22,21 +22,21 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <BRepAdaptor_Surface.hxx>
|
||||
# include <BRepExtrema_DistShapeShape.hxx>
|
||||
# include <BRepGProp.hxx>
|
||||
# include <GCPnts_AbscissaPoint.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <gp_Circ.hxx>
|
||||
# include <gp_Torus.hxx>
|
||||
# include <gp_Cylinder.hxx>
|
||||
# include <gp_Sphere.hxx>
|
||||
# include <gp_Lin.hxx>
|
||||
# include <GProp_GProps.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Shape.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepExtrema_DistShapeShape.hxx>
|
||||
#include <BRepGProp.hxx>
|
||||
#include <GCPnts_AbscissaPoint.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Torus.hxx>
|
||||
#include <gp_Cylinder.hxx>
|
||||
#include <gp_Sphere.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <GProp_GProps.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace Measure;
|
||||
@@ -80,31 +80,31 @@ bool Measurement::has3DReferences()
|
||||
return (References3D.getSize() > 0);
|
||||
}
|
||||
|
||||
//add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject *obj, const std::string& subName)
|
||||
// add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject* obj, const std::string& subName)
|
||||
{
|
||||
return addReference3D(obj,subName.c_str());
|
||||
return addReference3D(obj, subName.c_str());
|
||||
}
|
||||
|
||||
///add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject *obj, const char* subName)
|
||||
/// add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject* obj, const char* subName)
|
||||
{
|
||||
std::vector<App::DocumentObject*> objects = References3D.getValues();
|
||||
std::vector<std::string> subElements = References3D.getSubValues();
|
||||
std::vector<App::DocumentObject*> objects = References3D.getValues();
|
||||
std::vector<std::string> subElements = References3D.getSubValues();
|
||||
|
||||
objects.push_back(obj);
|
||||
subElements.emplace_back(subName);
|
||||
objects.push_back(obj);
|
||||
subElements.emplace_back(subName);
|
||||
|
||||
References3D.setValues(objects, subElements);
|
||||
References3D.setValues(objects, subElements);
|
||||
|
||||
measureType = findType();
|
||||
return References3D.getSize();
|
||||
measureType = findType();
|
||||
return References3D.getSize();
|
||||
}
|
||||
|
||||
MeasureType Measurement::findType()
|
||||
{
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
@@ -123,18 +123,18 @@ MeasureType Measurement::findType()
|
||||
int spheres = 0;
|
||||
int vols = 0;
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
|
||||
// Check if solid object
|
||||
if(strcmp((*subEl).c_str(), "") == 0) {
|
||||
if (strcmp((*subEl).c_str(), "") == 0) {
|
||||
vols++;
|
||||
}
|
||||
else {
|
||||
|
||||
TopoDS_Shape refSubShape;
|
||||
try {
|
||||
refSubShape = Part::Feature::getShape(*obj,(*subEl).c_str(),true);
|
||||
if(refSubShape.IsNull()){
|
||||
refSubShape = Part::Feature::getShape(*obj, (*subEl).c_str(), true);
|
||||
if (refSubShape.IsNull()) {
|
||||
return MeasureType::Invalid;
|
||||
}
|
||||
}
|
||||
@@ -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,24 +181,23 @@ MeasureType Measurement::findType()
|
||||
else if (sf.GetType() == GeomAbs_Torus) {
|
||||
torus++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(vols > 0) {
|
||||
if(verts > 0 || edges > 0 || faces > 0) {
|
||||
if (vols > 0) {
|
||||
if (verts > 0 || edges > 0 || faces > 0) {
|
||||
mode = MeasureType::Invalid;
|
||||
}
|
||||
else {
|
||||
mode = MeasureType::Volumes;
|
||||
}
|
||||
}
|
||||
else if(faces > 0) {
|
||||
if(verts > 0 || edges > 0) {
|
||||
else if (faces > 0) {
|
||||
if (verts > 0 || edges > 0) {
|
||||
if (faces == 1 && verts == 1) {
|
||||
mode = MeasureType::PointToSurface;
|
||||
}
|
||||
@@ -240,9 +234,9 @@ MeasureType Measurement::findType()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(edges > 0) {
|
||||
if(verts > 0) {
|
||||
if(verts > 1 && edges > 0) {
|
||||
else if (edges > 0) {
|
||||
if (verts > 0) {
|
||||
if (verts > 1 && edges > 0) {
|
||||
mode = MeasureType::Invalid;
|
||||
}
|
||||
else {
|
||||
@@ -287,11 +281,11 @@ MeasureType Measurement::getType()
|
||||
return measureType;
|
||||
}
|
||||
|
||||
TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subName) const
|
||||
TopoDS_Shape Measurement::getShape(App::DocumentObject* obj, const char* subName) const
|
||||
{
|
||||
//temporary fix to get "Vertex7" from "Body003.Pocket020.Vertex7"
|
||||
//when selected, Body features are provided as featureName and subNameAndIndex
|
||||
//other sources provide the full extended name with index
|
||||
// temporary fix to get "Vertex7" from "Body003.Pocket020.Vertex7"
|
||||
// when selected, Body features are provided as featureName and subNameAndIndex
|
||||
// other sources provide the full extended name with index
|
||||
if (strcmp(subName, "") == 0) {
|
||||
return Part::Feature::getShape(obj);
|
||||
}
|
||||
@@ -303,12 +297,12 @@ TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subNam
|
||||
|
||||
try {
|
||||
Part::TopoShape partShape = Part::Feature::getTopoShape(obj);
|
||||
App::GeoFeature* geoFeat = dynamic_cast<App::GeoFeature*>(obj);
|
||||
App::GeoFeature* geoFeat = dynamic_cast<App::GeoFeature*>(obj);
|
||||
if (geoFeat) {
|
||||
partShape.setPlacement(geoFeat->globalPlacement());
|
||||
}
|
||||
TopoDS_Shape shape = partShape.getSubShape(workingSubName.c_str());
|
||||
if(shape.IsNull()) {
|
||||
if (shape.IsNull()) {
|
||||
throw Part::NullShapeException("null shape in measurement");
|
||||
}
|
||||
return shape;
|
||||
@@ -323,64 +317,63 @@ 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
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
// TODO:: add lengthX, lengthY (and lengthZ??) support
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
double Measurement::length() const
|
||||
{
|
||||
double result = 0.0;
|
||||
int numRefs = References3D.getSize();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::length - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Invalid) {
|
||||
Base::Console().Error("Measurement::length - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
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();
|
||||
}
|
||||
else if(measureType == MeasureType::Edges || measureType == MeasureType::Line
|
||||
|| measureType == MeasureType::TwoLines || measureType == MeasureType::Circle) {
|
||||
else if (measureType == MeasureType::Edges || measureType == MeasureType::Line
|
||||
|| measureType == MeasureType::TwoLines || measureType == MeasureType::Circle) {
|
||||
|
||||
// Iterate through edges and calculate each length
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
//const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
//const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
// Get the length of one edge
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
// const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
// const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
// Get the length of one edge
|
||||
TopoDS_Shape shape = getShape(*obj, (*subEl).c_str());
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
|
||||
switch(curve.GetType()) {
|
||||
case GeomAbs_Line : {
|
||||
switch (curve.GetType()) {
|
||||
case GeomAbs_Line: {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result += diff.Modulus();
|
||||
break;
|
||||
}
|
||||
case GeomAbs_Circle : {
|
||||
case GeomAbs_Circle: {
|
||||
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;
|
||||
double range = v - u;
|
||||
result += radius * range;
|
||||
break;
|
||||
}
|
||||
@@ -392,10 +385,11 @@ 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
|
||||
} // end switch
|
||||
} // end for
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -489,45 +484,44 @@ double Measurement::planePlaneDistance() const {
|
||||
return distance;
|
||||
}
|
||||
|
||||
double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
double Measurement::angle(const Base::Vector3d& /*param*/) const
|
||||
{
|
||||
//TODO: do these references arrive as obj+sub pairs or as a struct of obj + [subs]?
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
// TODO: do these references arrive as obj+sub pairs or as a struct of obj + [subs]?
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
int numRefs = objects.size();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
throw Base::RuntimeError("No references available for angle measurement");
|
||||
}
|
||||
else if (measureType == MeasureType::Invalid) {
|
||||
throw Base::RuntimeError("MeasureType is Invalid for angle measurement");
|
||||
}
|
||||
else if(measureType == MeasureType::TwoLines) {
|
||||
//Only case that is supported is edge to edge
|
||||
//The angle between two skew lines is measured by the angle between one line (A)
|
||||
//and a line (B) with the direction of the second through a point on the first line.
|
||||
//Since we don't know if the directions of the lines point in the same general direction
|
||||
//we could get the angle we want or the supplementary angle.
|
||||
if(numRefs == 2) {
|
||||
else if (measureType == MeasureType::TwoLines) {
|
||||
// Only case that is supported is edge to edge
|
||||
// The angle between two skew lines is measured by the angle between one line (A)
|
||||
// and a line (B) with the direction of the second through a point on the first line.
|
||||
// Since we don't know if the directions of the lines point in the same general direction
|
||||
// we could get the angle we want or the supplementary angle.
|
||||
if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
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();
|
||||
gp_Dir dir2 = curve2.Line().Direction();
|
||||
gp_Dir dir2r = curve2.Line().Direction().Reversed();
|
||||
|
||||
gp_Lin l1 = gp_Lin(pnt1First, dir1); // (A)
|
||||
gp_Lin l2 = gp_Lin(pnt1First, dir2); // (B)
|
||||
gp_Lin l1 = gp_Lin(pnt1First, dir1); // (A)
|
||||
gp_Lin l2 = gp_Lin(pnt1First, dir2); // (B)
|
||||
gp_Lin l2r = gp_Lin(pnt1First, dir2r); // (B')
|
||||
Standard_Real aRad = l1.Angle(l2);
|
||||
double aRadr = l1.Angle(l2r);
|
||||
return std::min(aRad, aRadr) * 180 / M_PI;
|
||||
return std::min(aRad, aRadr) * 180 / M_PI;
|
||||
}
|
||||
else {
|
||||
throw Base::RuntimeError("Measurement references must both be lines");
|
||||
@@ -538,15 +532,14 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
}
|
||||
}
|
||||
else if (measureType == MeasureType::Points) {
|
||||
//NOTE: we are calculating the 3d angle here, not the projected angle
|
||||
//ASSUMPTION: the references are in end-apex-end order
|
||||
if(numRefs == 3) {
|
||||
// NOTE: we are calculating the 3d angle here, not the projected angle
|
||||
// ASSUMPTION: the references are in end-apex-end order
|
||||
if (numRefs == 3) {
|
||||
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));
|
||||
@@ -557,7 +550,7 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
gp_Lin line0 = gp_Lin(gEnd0, gDir0);
|
||||
gp_Lin line1 = gp_Lin(gEnd1, gDir1);
|
||||
double radians = line0.Angle(line1);
|
||||
return radians * 180 / M_PI;
|
||||
return radians * 180 / M_PI;
|
||||
}
|
||||
}
|
||||
throw Base::RuntimeError("Unexpected error for angle measurement");
|
||||
@@ -569,7 +562,7 @@ double Measurement::radius() const
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
int numRefs = References3D.getSize();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::radius - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Circle) {
|
||||
@@ -577,11 +570,12 @@ double Measurement::radius() const
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
if(curve.GetType() == GeomAbs_Circle) {
|
||||
return (double) curve.Circle().Radius();
|
||||
if (curve.GetType() == GeomAbs_Circle) {
|
||||
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);
|
||||
|
||||
@@ -603,7 +597,7 @@ double Measurement::radius() const
|
||||
Base::Vector3d Measurement::delta() const
|
||||
{
|
||||
Base::Vector3d result;
|
||||
int numRefs = References3D.getSize();
|
||||
int numRefs = References3D.getSize();
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::delta - No 3D references available\n");
|
||||
}
|
||||
@@ -611,11 +605,11 @@ Base::Vector3d Measurement::delta() const
|
||||
Base::Console().Error("Measurement::delta - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
if(measureType == MeasureType::PointToPoint) {
|
||||
if(numRefs == 2) {
|
||||
if (measureType == MeasureType::PointToPoint) {
|
||||
if (numRefs == 2) {
|
||||
// Keep separate case for two points to reduce need for complex algorithm
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
@@ -629,17 +623,19 @@ 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) {
|
||||
if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
BRepExtrema_DistShapeShape extrema(shape1, shape2);
|
||||
|
||||
if(extrema.IsDone()) {
|
||||
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();
|
||||
@@ -647,21 +643,21 @@ Base::Vector3d Measurement::delta() const
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(measureType == MeasureType::Edges) {
|
||||
else if (measureType == MeasureType::Edges) {
|
||||
// Only case that is supported is straight line edge
|
||||
if(numRefs == 1) {
|
||||
if (numRefs == 1) {
|
||||
TopoDS_Shape shape = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
|
||||
if(curve.GetType() == GeomAbs_Line) {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result = Base::Vector3d(diff.X(), diff.Y(), diff.Z());
|
||||
if (curve.GetType() == GeomAbs_Line) {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result = Base::Vector3d(diff.X(), diff.Y(), diff.Z());
|
||||
}
|
||||
}
|
||||
else if(numRefs == 2) {
|
||||
else if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
@@ -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()) {
|
||||
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();
|
||||
@@ -720,9 +716,9 @@ double Measurement::area() const
|
||||
Base::Console().Error("Measurement::area - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Volumes || measureType == MeasureType::Surfaces
|
||||
|| measureType == MeasureType::Cylinder || measureType == MeasureType::Cone
|
||||
|| measureType == MeasureType::Sphere || measureType == MeasureType::Torus
|
||||
|| measureType == MeasureType::Plane) {
|
||||
|| measureType == MeasureType::Cylinder || measureType == MeasureType::Cone
|
||||
|| measureType == MeasureType::Sphere || measureType == MeasureType::Torus
|
||||
|| measureType == MeasureType::Plane) {
|
||||
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
@@ -742,7 +738,7 @@ double Measurement::area() const
|
||||
Base::Vector3d Measurement::massCenter() const
|
||||
{
|
||||
Base::Vector3d result;
|
||||
int numRefs = References3D.getSize();
|
||||
int numRefs = References3D.getSize();
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::massCenter - No 3D references available\n");
|
||||
}
|
||||
@@ -750,18 +746,18 @@ Base::Vector3d Measurement::massCenter() const
|
||||
Base::Console().Error("Measurement::massCenter - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
GProp_GProps gprops = GProp_GProps();
|
||||
|
||||
if(measureType == MeasureType::Volumes) {
|
||||
if (measureType == MeasureType::Volumes) {
|
||||
// Iterate through edges and calculate each length
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
//const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
//const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
// const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
// const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
|
||||
// Compute inertia properties
|
||||
|
||||
@@ -771,20 +767,22 @@ Base::Vector3d Measurement::massCenter() const
|
||||
// Get inertia properties
|
||||
}
|
||||
|
||||
//double mass = gprops.Mass();
|
||||
// double mass = gprops.Mass();
|
||||
gp_Pnt cog = gprops.CentreOfMass();
|
||||
|
||||
return Base::Vector3d(cog.X(), cog.Y(), cog.Z());
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -866,11 +865,11 @@ unsigned int Measurement::getMemSize() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *Measurement::getPyObject()
|
||||
PyObject* Measurement::getPyObject()
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new MeasurementPy(this),true);
|
||||
PythonObject = Py::Object(new MeasurementPy(this), true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
@@ -36,32 +36,34 @@
|
||||
class TopoDS_Shape;
|
||||
namespace Measure
|
||||
{
|
||||
enum class MeasureType {
|
||||
Volumes, // Measure the Volume(s)
|
||||
Edges, // Measure the Edge(s)
|
||||
Line, // One Line
|
||||
TwoLines, // Two lines
|
||||
TwoParallelLines, // Two parallel lines
|
||||
Circle, // One circle
|
||||
Surfaces, // Measure the surface(s)
|
||||
Cylinder, // One Cylinder
|
||||
Cone, // One Cone
|
||||
Sphere, // One Sphere
|
||||
Torus, // One Torus
|
||||
Plane, // One Plane
|
||||
TwoPlanes, // One Plane
|
||||
Points,
|
||||
PointToPoint, // Measure between TWO points
|
||||
PointToEdge, // Measure between ONE point and ONE edge
|
||||
PointToSurface, // Measure between ONE point and ONE surface
|
||||
EdgeToEdge, // Measure between TWO edges
|
||||
Invalid
|
||||
};
|
||||
enum class MeasureType
|
||||
{
|
||||
Volumes, // Measure the Volume(s)
|
||||
Edges, // Measure the Edge(s)
|
||||
Line, // One Line
|
||||
TwoLines, // Two lines
|
||||
TwoParallelLines, // Two parallel lines
|
||||
Circle, // One circle
|
||||
Surfaces, // Measure the surface(s)
|
||||
Cylinder, // One Cylinder
|
||||
Cone, // One Cone
|
||||
Sphere, // One Sphere
|
||||
Torus, // One Torus
|
||||
Plane, // One Plane
|
||||
TwoPlanes, // One Plane
|
||||
Points,
|
||||
PointToPoint, // Measure between TWO points
|
||||
PointToEdge, // Measure between ONE point and ONE edge
|
||||
PointToSurface, // Measure between ONE point and ONE surface
|
||||
EdgeToEdge, // Measure between TWO edges
|
||||
Invalid
|
||||
};
|
||||
|
||||
class MeasureExport Measurement: public Base::BaseClass
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
class MeasureExport Measurement : public Base::BaseClass {
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
public:
|
||||
|
||||
App::PropertyLinkSubList References3D;
|
||||
|
||||
public:
|
||||
@@ -73,51 +75,55 @@ public:
|
||||
|
||||
/// Add a reference
|
||||
int addReference3D(App::DocumentObject* obj, const std::string& subName);
|
||||
int addReference3D(App::DocumentObject* obj, const char *subName);
|
||||
int addReference3D(App::DocumentObject* obj, const char* subName);
|
||||
|
||||
MeasureType getType();
|
||||
MeasureType findType();
|
||||
|
||||
// from base class
|
||||
PyObject *getPyObject() override;
|
||||
// from base class
|
||||
PyObject* getPyObject() override;
|
||||
virtual unsigned int getMemSize() const;
|
||||
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
double length() const;
|
||||
Base::Vector3d delta() const; //when would client use delta??
|
||||
double lineLineDistance() const;
|
||||
double planePlaneDistance() const;
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
double length() const;
|
||||
Base::Vector3d delta() const; // when would client use delta??
|
||||
double lineLineDistance() const;
|
||||
double planePlaneDistance() const;
|
||||
|
||||
// Calculates the radius for an arc or circular edge
|
||||
double radius() const;
|
||||
// Calculates the radius for an arc or circular edge
|
||||
double radius() const;
|
||||
|
||||
// Calculates the angle between two edges
|
||||
double angle(const Base::Vector3d ¶m = Base::Vector3d(0,0,0)) const; //param is never used???
|
||||
// Calculates the angle between two edges
|
||||
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;
|
||||
// Calculate the center of mass
|
||||
Base::Vector3d massCenter() const;
|
||||
|
||||
// Calculate the volume of selected volumes
|
||||
double volume() const;
|
||||
// Calculate the volume of selected volumes
|
||||
double volume() const;
|
||||
|
||||
// Calculate the area of selection
|
||||
double area() const;
|
||||
// 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;
|
||||
bool planesAreParallel() const;
|
||||
bool linesAreParallel() const;
|
||||
|
||||
protected:
|
||||
TopoDS_Shape getShape(App::DocumentObject *obj , const char *subName) const;
|
||||
TopoDS_Shape getShape(App::DocumentObject* obj, const char* subName) const;
|
||||
|
||||
private:
|
||||
MeasureType measureType;
|
||||
Py::SmartPtr PythonObject;
|
||||
MeasureType measureType;
|
||||
Py::SmartPtr PythonObject;
|
||||
};
|
||||
|
||||
|
||||
} //namespace measure
|
||||
} // namespace Measure
|
||||
|
||||
|
||||
#endif // MEASURE_MEASUREMENT_H
|
||||
#endif // MEASURE_MEASUREMENT_H
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -42,7 +42,7 @@ std::string MeasurementPy::representation() const
|
||||
return "<Measure::Measurement>";
|
||||
}
|
||||
|
||||
PyObject *MeasurementPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
PyObject* MeasurementPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of BoundBoxPy and the Twin object
|
||||
return new MeasurementPy(new Measurement);
|
||||
@@ -51,18 +51,19 @@ PyObject *MeasurementPy::PyMake(struct _typeobject *, PyObject *, PyObject *) /
|
||||
// constructor method
|
||||
int MeasurementPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::addReference3D(PyObject *args)
|
||||
PyObject* MeasurementPy::addReference3D(PyObject* args)
|
||||
{
|
||||
char *ObjectName;
|
||||
char *SubName;
|
||||
if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName,&SubName))
|
||||
char* ObjectName;
|
||||
char* 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);
|
||||
App::DocumentObject* Obj = App::GetApplication().getActiveDocument()->getObject(ObjectName);
|
||||
if (!Obj) {
|
||||
std::stringstream str;
|
||||
str << ObjectName << "does not exist in the document";
|
||||
@@ -71,7 +72,7 @@ PyObject* MeasurementPy::addReference3D(PyObject *args)
|
||||
}
|
||||
|
||||
// add the external
|
||||
if (this->getMeasurementPtr()->addReference3D(Obj,SubName) < 0) {
|
||||
if (this->getMeasurementPtr()->addReference3D(Obj, SubName) < 0) {
|
||||
std::stringstream str;
|
||||
str << "Not able to add reference";
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
@@ -81,11 +82,12 @@ PyObject* MeasurementPy::addReference3D(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::has3DReferences(PyObject *args)
|
||||
PyObject* MeasurementPy::has3DReferences(PyObject* args)
|
||||
{
|
||||
PyObject *result=Py_False;
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
PyObject* result = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (getMeasurementPtr()->has3DReferences()) {
|
||||
result = Py_True;
|
||||
@@ -95,30 +97,33 @@ PyObject* MeasurementPy::has3DReferences(PyObject *args)
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::clear(PyObject *args)
|
||||
PyObject* MeasurementPy::clear(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
this->getMeasurementPtr()->clear();
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::delta(PyObject *args)
|
||||
PyObject* MeasurementPy::delta(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Vector delta(this->getMeasurementPtr()->delta());
|
||||
|
||||
return Py::new_reference_to(delta);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::length(PyObject *args)
|
||||
PyObject* MeasurementPy::length(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float length;
|
||||
length = this->getMeasurementPtr()->length();
|
||||
@@ -126,10 +131,11 @@ PyObject* MeasurementPy::length(PyObject *args)
|
||||
return Py::new_reference_to(length);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::lineLineDistance(PyObject *args)
|
||||
PyObject* MeasurementPy::lineLineDistance(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float length;
|
||||
length = this->getMeasurementPtr()->lineLineDistance();
|
||||
@@ -137,10 +143,11 @@ PyObject* MeasurementPy::lineLineDistance(PyObject *args)
|
||||
return Py::new_reference_to(length);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::planePlaneDistance(PyObject *args)
|
||||
PyObject* MeasurementPy::planePlaneDistance(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float length;
|
||||
length = this->getMeasurementPtr()->planePlaneDistance();
|
||||
@@ -148,10 +155,11 @@ PyObject* MeasurementPy::planePlaneDistance(PyObject *args)
|
||||
return Py::new_reference_to(length);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::volume(PyObject *args)
|
||||
PyObject* MeasurementPy::volume(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float length;
|
||||
length = this->getMeasurementPtr()->volume();
|
||||
@@ -159,10 +167,11 @@ PyObject* MeasurementPy::volume(PyObject *args)
|
||||
return Py::new_reference_to(length);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::area(PyObject *args)
|
||||
PyObject* MeasurementPy::area(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float length;
|
||||
length = this->getMeasurementPtr()->area();
|
||||
@@ -170,10 +179,11 @@ PyObject* MeasurementPy::area(PyObject *args)
|
||||
return Py::new_reference_to(length);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::radius(PyObject *args)
|
||||
PyObject* MeasurementPy::radius(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float radius;
|
||||
radius = this->getMeasurementPtr()->radius();
|
||||
@@ -181,10 +191,11 @@ PyObject* MeasurementPy::radius(PyObject *args)
|
||||
return Py::new_reference_to(radius);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::angle(PyObject *args)
|
||||
PyObject* MeasurementPy::angle(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Float angle;
|
||||
angle = this->getMeasurementPtr()->angle();
|
||||
@@ -192,17 +203,18 @@ PyObject* MeasurementPy::angle(PyObject *args)
|
||||
return Py::new_reference_to(angle);
|
||||
}
|
||||
|
||||
PyObject* MeasurementPy::com(PyObject *args)
|
||||
PyObject* MeasurementPy::com(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Vector com(this->getMeasurementPtr()->massCenter());
|
||||
|
||||
return Py::new_reference_to(com);
|
||||
}
|
||||
|
||||
PyObject *MeasurementPy::getCustomAttributes(const char* /*attr*/) const
|
||||
PyObject* MeasurementPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -46,4 +46,4 @@
|
||||
|
||||
#endif //_PreComp_
|
||||
|
||||
#endif // MEASUREGUI_PRECOMPILED_H
|
||||
#endif // MEASUREGUI_PRECOMPILED_H
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <string>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -32,35 +32,41 @@
|
||||
#include "Preferences.h"
|
||||
|
||||
|
||||
//getters for parameters used in multiple places.
|
||||
//ensure this is in sync with parameter names and default values on preference pages
|
||||
// getters for parameters used in multiple places.
|
||||
// ensure this is in sync with parameter names and default values on preference pages
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Color;
|
||||
namespace Measure
|
||||
{
|
||||
|
||||
//getters for parameters used in multiple places.
|
||||
// getters for parameters used in multiple places.
|
||||
class MeasureExport Preferences
|
||||
{
|
||||
|
||||
@@ -51,6 +51,5 @@ public:
|
||||
};
|
||||
|
||||
|
||||
}//end namespace Measure
|
||||
} // end namespace Measure
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user